使用相同的登录页面在laravel上进行多重身份验证

时间:2019-04-13 15:23:51

标签: laravel

我正在一个有Admin和Employee的项目中,我希望此用户中的两个使用laravel提供的登录表单登录。这两个用户有一个单独的表。

这是我定义的守卫;

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'admins',
    ],

    'employee' => [
        'driver' => 'session',
        'provider' => 'employees',
    ],

    'api' => [
        'driver' => 'token',
        'provider' => 'users',
        'hash' => false,
    ],
],


 'providers' => [
    'admins' => [
        'driver' => 'eloquent',
        'model' => App\Admin::class,
    ],

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

],

然后我在attemptLogin中覆盖了LoginController

protected function attemptLogin(Request $request){
$customerAttempt = Auth::guard('employee')->attempt(
    $this->credentials($request), $request->has('remember')
);
if(!$customerAttempt){
    return Auth::guard()->attempt(
        $this->credentials($request), $request->has('remember')
    );
} 
return $customerAttempt;


}

但是无法正常工作...我无法使用员工用户登录,当我null时它总是返回dd(Auth::user());

0 个答案:

没有答案