Laravel 7 change the default guard to employee but the current authenticated user return null

Viewed 185

I changed the default guard to something like below

auth.php

 'defaults' => [
            'guard' => 'employee',
            'passwords' => 'users',
        ],
    
 'guards' => [
            'employee' => [
                'driver' => 'session',
                'provider' => 'employees',
            ],
        ],

 'providers' => [
        
         'employees' => [
            'driver' => 'eloquent',
            'model' => App\Employee::class,
        ],
    ],

However, I can't get the current login user from this Auth facade Auth::guard('employee')->user() this returns an empty result.

But the user login work successfully Auth::attempt(['email' => $request->email, 'password' => $request->password, 'status' => 1])

I really appreciate your help.

Thanks

1 Answers

Thanks for the viewers. Instead of using Auth::guard('employee')->user() facade, I tried login method $request call. It works for me. $request->user();

public function login(Request $request){
  $request->user();
}
Related