spatie / laravel-permission

Associate users with roles and permissions
https://spatie.be/docs/laravel-permission
MIT License
12.2k stars 1.78k forks source link

Problems using UUID There is no [permission] with ID `85d49adb-e164-41e5-afd2-3e3c45af660a` for guard `web`. #2737

Open josecastro22 opened 1 month ago

josecastro22 commented 1 month ago

Description

Im using this seeder to create an admin user and assing all roles in database

        $user = User::create([
            'email' => 'admin@domain.com',
            'password' => 'password',
        ]);

        $perfil = Perfil::create([
            'user_id' => $user->id,
            'name' => 'Admin',
            'last_name' => 'App',
        ]);

        $role = Role::create(['name' => 'admin']);

        $permissions = Permission::pluck('uuid', 'uuid')->all();

        $role->syncPermissions($permissions);

        $user->assignRole([$role->uuid]);

The problem its when execute $role->syncPermissions($permissions); i get this error

There is no [permission] with ID 488a71c3-d01b-45fc-8fee-03422322c4ec for guard web.

I follow the error and come to

vendor\spatie\laravel-permission\src\Traits\HasPermissions.php:491

So i encountered with this line

return $this->getPermissionClass()::findById($permissions, $this->getDefaultGuardName());

So i try to get the Permission just using

Permission::findById('488a71c3-d01b-45fc-8fee-03422322c4ec', 'web')

And there is not problem. So what its wrong?

Steps To Reproduce

1. 2. 3. ...

Example Application

No response

Version of spatie/laravel-permission package:

^6.9

Version of laravel/framework package:

^11.9

PHP version:

^8.2

Database engine and version:

No response

OS: Windows/Mac/Linux version:

No response

parallels999 commented 1 month ago

Seems like cache problem again, there are many similar threads

drbyte commented 1 month ago

Yes, could be a cache issue, or perhaps something incomplete with the UUID configuration that's causing -> getKeyName() to not return the correct field name.