Configure model names from package? #1864
Unanswered
timschwartz
asked this question in
Q&A
Replies: 1 comment 2 replies
-
it is because that does not work, at start package uses model from config file, changes after that have no effect laravel-permission/config/permission.php Lines 16 to 27 in 2512d5a |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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