Deleting permission in spatie package

  Sat 20 / 07 / 2024

  Posted by: Talha Manzoor

Category : Laravel

Tags : laravel , php laravel , backend

Post Thumbnail
Description

I am using spatie permssion package and created resource controller for Permission  CRUD, only destroy() metohd is not working and giving error at  $permission->delete();


View Code
                        use Spatie\Permission\Models\Permission;

 public function destroy(Permission $permission): RedirectResponse
    {
        $permission->delete();
        return to_route('permissions.index')->with('message', 'Permission deleted successfully');
    }
                
  Answered by CDL

In spatie if you want to delete the assign role, you need to call the revoke method to unlink the permission rather than deleting the permission itself.


How to do that:

~~~

$role->revokePermissionTo($permission);

~~~


Then this permission will be unlinked from the user or role.

  Comment   Share
0 Likes   0 Comments