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.
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/
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/