1

Following error has occured while I try to check permissions in Event after login and add some to User if he does not have assigned:

Spatie  \  Permission  \  Exceptions  \  PermissionDoesNotExist There is no permission named ABR for guard web.

What's so funnier, I've tried already to follow this post:

spatie/laravel-permission There is no permission named edit_project for guard api

But the cache clearing direct for Spatie : php artisan cache:forget spatie.permission.cache and then for whole app: php artisan cache:clear did not help.

What I wanted to do is to handle event after User login, that assigns the permission to his model. Short demo:

     /**
     * Handle the event.
     *
     * @param  \Illuminate\Auth\Events\Login  $event
     * @return void
     */
    public function handle(Login $event)
    {
        $event->user->givePermissionTo('ABR'); 
    }

My permissions are loaded through *.txt file, and then added to DB like Permission::create(['name'=>'ABR']); and so on.

Any idea how to fix this? guard_name is automatically assigned to web.

kalview
  • 135
  • 2
  • 13

1 Answers1

0

If you want to use the api guard, it's as simple as:

Permission::create(['name'=>'ABR', 'guard_name' => 'api']);
Parsa Safavi
  • 218
  • 2
  • 10