未登录重定向 Handler.php
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => 'Unauthenticated.'], 401);
}
$guards = $exception->guards();
if(is_array($guards) && !empty($guards)){
foreach ($guards as $guard) {
if ($guard == 'admin') {
return redirect()->guest('admin/login');
} else {
return redirect()->guest('login');
}
}
}
return redirect()->guest(route('login'));
}
控制器
登录成功跳转 Middleware/RedirectIfAuthenticated.php
视图
配置文件 config/auth.php
退出备注
public function logout()
{
$this->guard()->logout();
return redirect('admin/login');
}