我正在一个有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());