erezt
erezt

Reputation: 411

Laravel - 'Auth guard [admin] is not defined.'

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

Upvotes: 5

Views: 11478

Answers (2)

Mayur Panchal
Mayur Panchal

Reputation: 655

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.

Upvotes: 4

Heroselohim
Heroselohim

Reputation: 1291

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

Upvotes: 1

Related Questions