Created
June 3, 2018 11:46
-
-
Save xiaoysh8/3a989ef8871af3699ea88924cf8de680 to your computer and use it in GitHub Desktop.
laravel redirecting user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Redirecting Unauthenticated Users | |
| When the auth middleware detects an unauthorized user, it will either return a JSON 401 response, or, if the request was not an AJAX request, redirect the user to the login named route. | |
| You may modify this behavior by defining an unauthenticated function in your app/Exceptions/Handler.php file: | |
| use Illuminate\Auth\AuthenticationException; | |
| protected function unauthenticated($request, AuthenticationException $exception) | |
| { | |
| return $request->expectsJson() | |
| ? response()->json(['message' => $exception->getMessage()], 401) | |
| : redirect()->guest(route('login')); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment