skip to Main Content

I got the error when I assigned permission to the role by using Spatie permission with Laravel 10 the error is like this:

There is no permission named 2 for guard web.

Can anyone help me?

2

Answers


  1. try switching to old version of spatie permissions

    Login or Signup to reply.
  2. you are probably doing this

    $user->removeRole(2);  //this is not the right way
    
    OR
    
    $user->assignRole(2);  //this is not the right way
    

    Replace with this code

    $user->removeRole('writer');  //to remove the role pass the role_name
    
    OR
    
    $user->assignRole('writer'); // to add the role
    

    and this is the link where from you can get help

    https://spatie.be/docs/laravel-permission/v6/basic-usage/role-permissions#content-assigning-roles

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search