I have a problem with the spatie/laravel-permissions library.
Previously I had it implemented in my system but after doing composer update it stopped working...
The problem is when I add the HasRole in my User model. Everything crashes and I get the error: "Call to a member function first() on array " Making mention of the PermissionRegistrar package file.
Likewise, if I try to enter another route in my system, the error that appears is " Undefined index: name"
It should be noted that I have my model created, my tables in the database and I carry out the package installation process following the documentation, and as I said before, the roles and permissions system worked for me before.
Something I should mention is that I had previously replaced the "name" field with "description" but I had some configuration problems with the library so I ran another migration adding the Name field, which the library requires. After running the migration, everything seemed to work correctly
CodePudding user response:
You probably have a cache issue specifically related to Spatie. If you face any kind of issues when you are seeding your DB, you can add this line at the top of your seed within the run()
method
app()[\Spatie\Permission\PermissionRegistrar::class]->forgetCachedPermissions();
On the other hand, if you changed something manually, let's say from DB, you can try with artisan command
php artisan permission:cache-reset
https://spatie.be/docs/laravel-permission/v5/basic-usage/artisan#content-resetting-the-cache
Note that you need to clear cache even if you are running a fresh install by using
php artisan migrate:fresh --seed
CodePudding user response:
So you just ran a full update of all packages? That is kind of a scary situation, I don't think I've ever done a full update to all packages. I'm not sure what version of spatie you are coming or going with, that might help.
When I did a full update from Laravel 5.7 all the way to Laravel 8, spatie was a pain. Not just a little pain but a full on work for 4 days updating pain. All the database tables were renamed, more added. Then I had to write code to transfer 20k users and permissions over from the old tables to the new tables with correct relationships. Then I had to go though and use the newer functions...etc. Nightmare.
So as you can see you are a little vague in your question for a proper answer.