Zizaco / entrust

Role-based Permissions for Laravel 5
MIT License
6.05k stars 1.29k forks source link

How to remove a role? #702

Open shahidkarimi opened 7 years ago

shahidkarimi commented 7 years ago

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

vogtdominikgit commented 7 years ago

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

jameskandau commented 6 years ago

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