-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assign role for a particular model #592
Comments
This is a feature request that keeps on coming up, but it's more complicated than it sounds. Caching becomes really complicated. See here. In your case, you could use the Bouncer::allow($user)->toManage($post); This allows all abilities on that model. It's syntactic sugar for: Bouncer::allow($user)->to('*', $post); |
Ah okay, that makes sense. However, the solution you proposed allows all abilities on that model. But what if we need(as in my case), to only assign abilities of a particular role( that is not an admin or super admin, say editor). What I came up with though, is a little hack, which I'm 100% sure isnt a great solution at all and I haven't written custom tests for it. But it works.... I'd like your opinion on it please. I created a helper class called
Then used as follows:
|
Considering that it is possible to do grant an ability only to a specific model
I think it should also be possible to grant a role to a specific model. That is, take all the abilities a particular role has and give it to a user, but only for a particular model. That is:
Bouncer::assign('admin', $post)->to($user);
rather than just
Bouncer::assign('admin')->to($user);
The text was updated successfully, but these errors were encountered: