I'm hitting a roadblock using spatie's permissions package and wanted to reach out and see if anyone has successfully extended the package to handle the following situation:
Let's say I have 3 models, User Company, CompanyUser. A User belongsToMany Companies via CompanyUser.
I'd like a User to have global permissions afforded via the roles directly attached to the User model, but they should also inherit permissions for a specific Company given the role(s) on their CompanyUser record.
Issues:
$user->can('do something')will not take into account CompanyUser permissions- I don't think
Gate::allows()calls in controllers will play nicely either?
I don't know if I'm trying to do something stupid, but basically my thought is:
- When viewing a company page, i.e.
/companies/xyz$user->can('do something')orGate::allows()should take into account the company and also consider any CompanyUser permissions as part of the User. Can probably pass in$company->idto these methods. - Otherwise, just look at the User's permissions
In order to achieve this, I think I have to override both the ->can() method, how spatie creates the Gates, etc. and it's looking less and less like a neat solution.
TLDR;
How do you maintain global permissions + scoped permissons against another model for a User using spatie's permissions package? Is there another package that is more suited to this?