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

irenehavsa's avatar

Multiple Roles Problem

Hello, I'm new to Laravel and still have a lot to learn. I need some advice about user role on a project I'm working on.

I have a Distributor model and 2 user roles: Admin and Manager. The requirements are as follow:

  1. User can be an Admin on 1 Distributor. Can create, update, delete.
  2. User can be a Manager on several Distributors. Can view the combined summary of all Distributors they are on.
  3. User can be an Admin and Manager at the same time (ex: Admin on Distributor A + Manager on Distributor A and Distributor B).

In short, a User can have different roles on several Distributors. Now I'm not sure how to implement the User-Role-Distributor relationship. I'm using Sentinel and doing fine with 1 Distributor, but have no idea what to do next.

Or should I restrict the requirements so that a User can only have 1 role (Admin OR Manager)? That way I can add User-Distributor relationship to manage permissions. My only concern is that a person might need 2 account and juggling between them to get different access/permission.

Thank you!

0 likes
3 replies
Snapey's avatar
Snapey
Best Answer
Level 122

I would probably have two separate 'pivot' tables one would be admins and one managers

In each have a distributor_id and user_id column

You can then allocate one or more admins to a distributor, and one or more managers.

Its then fairly easy to check if the user is mentioned in the admin table for a specific distributor, or finding all the distributors for which the user is a manager

You could do it with a single table and an additional type column but this seems to unnecessarily complicate matters.

1 like
irenehavsa's avatar

Oh wow I never consider making the roles into tables. I'm going to try your solution and see how it turns out. Thanks a lot!

Vilfago's avatar

Maybe if you want to be sure that an admin is admin only for a distributor, add a unique constraint on the admins table (column user_id).

Or check it in your app ;)

1 like

Please or to participate in this conversation.