entrust icon indicating copy to clipboard operation
entrust copied to clipboard

How to remove a role?

Open shahidkarimi opened this issue 10 years ago • 2 comments

There is no method to remove a role from a user. How to do that?

shahidkarimi avatar Nov 22 '16 09:11 shahidkarimi

You search for the specific role in roles relation of the user like '$role = $user->roles()->where("name", "admin-role-name)->first()'

Then you just call '$user->roles()->detatch($role)'

Thats basicly it. Have in mind you add a many-to-many relation between user and roles. For further explanations i would refer to the laravel docs > eloquent > updating many to many relations.

Regards Dominik

vogtdominikgit avatar Nov 23 '16 12:11 vogtdominikgit

$roles = ['admin','su']; $user->detachRoles($roles);

jameskandau avatar Feb 08 '18 08:02 jameskandau