Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove all roles from the user in spatie/laravel-permission

whats the best or the usual way to remove all roles from a user?

I tried

$roles = $user->getRoleNames(); $user->removeRole($roles);

Return value of App\User::getStoredRole() must implement interface Spatie\Permission\Contracts\Role, instance of Illuminate\Support\Collection returned
like image 992
Smoky Avatar asked Oct 27 '25 13:10

Smoky


1 Answers

Use the plain Laravel detach method like so:

$user->roles()->detach();

like image 160
Paras Avatar answered Oct 30 '25 02:10

Paras