Home  >  Article  >  Backend Development  >  Jump address after auth middleware authentication failure in laravel5.3

Jump address after auth middleware authentication failure in laravel5.3

WBOY
WBOYOriginal
2016-12-01 00:25:521755browse

In laravel5.3, auth middleware is placed directly in illuminate and then it will be executed if the user is not logged in
Jump address after auth middleware authentication failure in laravel5.3

The default jump address is /login. I want to change the jump address to /user/login

5.2 is more understandable. What kind of implementation is 5.3 here?

Reply content:

In laravel5.3, auth middleware is placed directly in illuminate and then it will be executed if the user is not logged in
Jump address after auth middleware authentication failure in laravel5.3

The default jump address is /login. I want to change the jump address to /user/login

5.2 is more understandable. What kind of implementation is 5.3 here?

This requires modifying the appExceptionsHandler.php file. There is an unauthenticated method

at the bottom.
/**
 * Convert an authentication exception into an unauthenticated response.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  \Illuminate\Auth\AuthenticationException  $exception
 * @return \Illuminate\Http\Response
 */
protected function unauthenticated($request, AuthenticationException $exception)
{
    if ($request->expectsJson()) {
        return response()->json(['error' => 'Unauthenticated.'], 401);
    }
    // 这里的login修改为user/login
    return redirect()->guest('login');
}

Custom redirect?

return redirect()->route('user.login');
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn