Laravel中涉及认证跳转地址的修改的地方

登录后跳转:

app\Http\Auth\LoginController.php中修改

protected $redirectTo = '/home';

已登录,访问登录接口时跳转:

修改app\Http\Middleware\RedirectIfAuthenticated.php中的handle()方法:

 public function handle($request, Closure $next, $guard = null)
 {
   if (Auth::guard($guard)->check()) {
       return redirect('/home');
   }

   return $next($request);
 }

未登录访问需要登录页面时的跳转

修改app\Http\Exceptions\Handler.php中的unauthenticated()方法:

protected function unauthenticated($request, AuthenticationException $exception)
{
    if ($request->expectsJson()) {
        return response()->json(['error' => 'Unauthenticated.'], 401);
    }
    return redirect()->guest(route('login'));
}
Copyright © http://blog.webfsd.com 2018 all right reserved,powered by Gitbook该文件修订时间: 2019-05-21 04:55:26

results matching ""

    No results matching ""