我有2种类型的用户(simpleUser和admin),我通过数据库中的属性角色将它们分开。因此,我想使双重登录重定向回到属性角色。
答案 0 :(得分:0)
LoginController:
public function login(Request $request)
{
$this->validateLogin($request);
if($this->guard()->validate($this->credentials($request))) {
if(Auth::attempt(['email' => $request->email, 'password' => $request->password)) {
if(Auth::user()->role == 'admin') {
return redirect('adminpage');
} else {
return redirect('clientpage');
}
}
} else {
return response()->json([
'error' => 'Credentials do not match our database.'
], 401);
}
}