Laravel-permission: remove all permissions for a given role?

Created on 26 Apr 2020  路  1Comment  路  Source: spatie/laravel-permission

i'm sorry if this question has been asked here before with other words, i just couldn't find it anywhere.

basically, i'm trying to create a roles CRUD that can have N permissions, in the update process i remove all permissions assigned to the role and then assigned only the ones that were sent through the form, i know i can just use plain sql to remove all role_id from role_has_permissions, but i was wondering if there's something like: $role->revokeAllPermissions() natively?
or if there's a better approach...

really appreacite it, thanks for this wonderful package.

support

Most helpful comment

You can use $role->syncPermissions($permissionsArrayOrCollection) for that.
It will natively detach all prior permissions and attach only the ones you provide.

Internally it simply uses Laravel's attach/detach/sync methods from Eloquent, but applied specifically to the models and tables used by this package.

You can read more about the available methods for this package in
https://docs.spatie.be/laravel-permission/v3/basic-usage/basic-usage/

>All comments

You can use $role->syncPermissions($permissionsArrayOrCollection) for that.
It will natively detach all prior permissions and attach only the ones you provide.

Internally it simply uses Laravel's attach/detach/sync methods from Eloquent, but applied specifically to the models and tables used by this package.

You can read more about the available methods for this package in
https://docs.spatie.be/laravel-permission/v3/basic-usage/basic-usage/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tripex picture tripex  路  3Comments

feliperoan picture feliperoan  路  3Comments

wreighsantos picture wreighsantos  路  4Comments

dylangeorgeharbour picture dylangeorgeharbour  路  3Comments

holymp2006 picture holymp2006  路  4Comments