Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Gizmo's avatar

Roles and Permissions with Companies

Hi Everyone,

I've watched this tutorial -> https://laracasts.com/series/whats-new-in-laravel-5-1/episodes/16 and thought its great. However what i want to do is actually slightly different from this.

I want users to be able to have companies, with roles within that company.

Lets say, we've got 3 users, 3 companies and 3 roles.

James

ABC Motors

    Web Developer

    Accountant

iMouseComp

    Accountant

Jimmy

ABC Motors

    Web Developer

Peter

iMouseComp

    Administrator

WebBasic

    Web Developer

    Administrator

Now, what Jeffrey has created is brilliant, if you only have 1 company.

I'm just having a hard time splitting it up over different companies. help would be lovely.

Thanks for reading.

Daniel.

0 likes
2 replies
jekinney's avatar

Possibly think of your companies as teams.

What I do is add a column to my roles table that links a team, your case company, in the roles table. When a company is created I also create a role with all permissions and assign the team id too. The user that created the team is assigned that role (owner). The owner then can create specific roles and attach permissions dynamically.

Otherwise it's pretty much the same as a basic roles and permissions. The sites roles will have a 0 by default in the team_id column. So in my hasRole method if I pass a team id it looks for a role with that team_id of I don't it looks for a global role (0).

hasPermission method same deal. If I pass a team_id it insures a user has permission assigned to the users role with the team_id or if not passed through global role.

1 like

Please or to participate in this conversation.