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