You can use role(s) for this. A user can have an ability through either role permissions or direct permissions. The Authorization Gate is not concerned how a User has the ability; only that it has the ability. So you can give the role appropriate permissions; and supplement individual users with direct permissions.
Best practices for ACL/Authorization
I'm building a large scale app that will have dozens (perhaps hundreds) of separate permissions. I'm looking at Spatie's Laravel-Permission package for ACL, but struggling to figure out exactly how to use it. The business owner wants to be able to fine tune what actions his employees can perform in the website.
Example Use Cases:
- Admin 1 is able to "impersonate users", "view sales history", "create users", and "delete users"
- Admin 2 is able to "view sales history", and "create users"
- Admin 3 is able to "view sales history"
This is an obviously oversimplified example that could be accomplished with 3 separate roles. However, there are dozens of users, and there will be many, many permissions. The potential permissions combinations will be so large that trying to define all of the scenarios into separate roles would be impossible/impractical.
For those who have dealt with this problem, what solution did you go with? I'm open to other packages, or none at all if it's easier to implement with pure gates and policies.
My current thoughts are instead of assigning permissions to roles, assign them to users directly via Spatie's Direct Permissions feature, and testing by hasDirectPermission() instead of testing by roles.
In theory it sounds good, but I'm not sure how it will work out in practice. Thoughts?
@scott80109 You can assign both roles and direct permissions, as I have done here;
https://www.evernote.com/l/AAZb5x4ozoRNJ6Gk3kXR_yxX9cAMdpG31Bo
This is from https://github.com/snapey/r4fb
Please or to participate in this conversation.