Remove All Roles from specific role #1789
Replies: 3 comments 4 replies
-
$role = Role::findByName('foo'); // or findById() or find()
$role->permissions->each(function ($role) {
$role->delete();
}); |
Beta Was this translation helpful? Give feedback.
-
Maybe better performance when you have a lot of permissions $role = Role::findByName('member'); // for get id by name
\DB::table(config('permission.table_names.role_has_permissions'))->where('role_id',$role->id)->delete();
$role->forgetCachedPermissions(); @drbyte is |
Beta Was this translation helpful? Give feedback.
-
$role = Role::findByName('member'); // get role by name
// Detach all permissions from the role...
$role->permissions()->detach();
// Rebuild the cache
$role->forgetCachedPermissions(); Also, maybe can work $role = Role::findByName('member');
$role->syncPermissions([]); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, is there any function to remove all permission attached for role?
let say I want to flush all permission from 'member' role
thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions