Home > Article > Backend Development > Jump address after auth middleware authentication failure in laravel5.3
In laravel5.3, auth middleware is placed directly in illuminate and then it will be executed if the user is not logged in
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?
In laravel5.3, auth middleware is placed directly in illuminate and then it will be executed if the user is not logged in
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
<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>
Custom redirect?
<code>return redirect()->route('user.login');</code>