Configure model names from package? #1902
Unanswered
timschwartz
asked this question in
Q&A
Replies: 1 comment
-
Also maybe you have to extend and overwrite laravel-permission/src/PermissionServiceProvider.php Lines 78 to 79 in 2512d5a |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Discussed in #1864
Originally posted by timschwartz September 18, 2021
I've setup spatie/laravel-permission to use UUIDs, this works fine as long as I include my custom Role/Permission models in config/permission.php.
However, I'm making a package and I'd like to do the configuration from my package provider:
$models = config('permission.models'); $models['permission'] = \ImperianSystems\CRM\Models\Permission::class; $models['role'] = \ImperianSystems\CRM\Models\Role::class; config(['permission.models'=>$models]);
Modifying config like this works for other things like auth.providers or auth.guards, but it doesn't work for permission.models.
In my code I print the current configuration and it shows that it is using my custom models, but when I actually try to add a role to a user it still uses Spatie's original model and I get an error because it treats role_id as an int instead of a UUID:
$u->assignRole('Administrator');
Illuminate\Database\QueryException with message 'SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (crm.model_has_roles, CONSTRAINT model_has_roles_role_id_foreign FOREIGN KEY ('role_id') REFERENCES roles ('id') ON DELETE CASCADE) (SQL: insert into model_has_roles ('model_id', 'model_type', 'role_id') values (0f987741-37bd-4e2a-bbbf-3909aeb42fa6, ImperianSystems\CRM\Models\User, 9))'
Beta Was this translation helpful? Give feedback.
All reactions