diff --git a/src/Illuminate/Foundation/Exceptions/Handler.php b/src/Illuminate/Foundation/Exceptions/Handler.php index 208391696099..3514402c806c 100644 --- a/src/Illuminate/Foundation/Exceptions/Handler.php +++ b/src/Illuminate/Foundation/Exceptions/Handler.php @@ -205,6 +205,20 @@ protected function prepareException(Exception $e) return $e; } + /** + * Convert an authentication exception into a response. + * + * @param \Illuminate\Http\Request $request + * @param \Illuminate\Auth\AuthenticationException $exception + * @return \Illuminate\Http\Response + */ + protected function unauthenticated($request, AuthenticationException $exception) + { + return $request->expectsJson() + ? response()->json(['message' => 'Unauthenticated.'], 401) + : redirect()->guest(route('login')); + } + /** * Create a response object from the given validation exception. *