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

Jump address after auth middleware authentication failure in laravel5.3

WBOY
Release: 2023-03-01 18:56:01
Original
1915 people have browsed it

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.
<code>/**
 * 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');
}</code>
Copy after login

Custom redirect?

<code>return redirect()->route('user.login');</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template