I have maybe altered something while dealing with permissions that could have altered the guard. I have no idea what since I can't see any git changes, maybe via the DB?
At first I tried to tinker and give a specific user admin privileges with:
$role = Spatie\Permission\Models\Role::where('name', 'admin')->get()->first();
When that returned undefined, I checked Auth::guard('admin')
, that returns undefined, so I understand that the issue has nothing to do with Spatie package.
After looking in a few questions/answers here on stackoverflow, one of them being config:clear
and config:cache
, which didn't work and still getting undefined for Auth guard admin.
Any other options I could take to get Auth admin?
thanks
In case you edited your config/auth.php, e.g. to add another guard and your config is cached, your guards may not be reloaded. If you experience this problem, clearing the config will fix it.
https://github.com/laravel/laravel/blob/v5.2.0/config/auth.php
php artisan config:clear OR php artisan config:cache
i'm using laravel 5.4
Add admin or administrator to the auth guards. After this php artisan config:clear can be run to remove the previous cached configurations. It should match your roles->name in the database.
\config\auth.php (file)
'guards' => [
...
'administrator' => [
'driver' => 'session',
'provider' => 'users',
],
],
An old question, but stil valid from Laravel 5 to 7
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With