-
Notifications
You must be signed in to change notification settings - Fork 336
Removing roles and abilities
The bouncer can also retract a previously-assigned role from a user:
Bouncer::retract('ban-users')->from($user);
Or do it directly on the user:
$user->retract('ban-users');
The bouncer can also remove an ability previously granted to a user:
Bouncer::disallow($user)->to('ban-users');
Or directly on the user:
$user->disallow('ban-users');
Note: if the user has a role that allows them to
ban-users
they will still have that ability. To disallow it, either remove the ability from the role or retract the role from the user.
If the ability has been granted through a role, tell the bouncer to remove the ability from the role instead:
Bouncer::disallow('admin')->to('ban-users');
To remove an ability for a specific model type, pass in its name as a second argument:
Bouncer::disallow($user)->to('delete', Post::class);
Warning: if the user has an ability to
delete
a specific$post
instance, the code above will not remove that ability. You will have to remove the ability separately - by passing in the actual$post
as a second argument - as shown below.
To remove an ability for a specific model instance, pass in the actual model instead:
Bouncer::disallow($user)->to('delete', $post);