handleExceptions($request, $exception); } return parent::render($request, $exception); } /** * Convert an authentication exception into a response. * * @param \Illuminate\Http\Request $request * @param \Illuminate\Auth\AuthenticationException $exception * @return \Symfony\Component\HttpFoundation\Response */ protected function unauthenticated($request, AuthenticationException $exception) { // Store the current url in the session session(['url.intended' => $request->url()]); return $request->expectsJson() ? response()->json(['message' => $exception->getMessage()], 401) : redirect()->guest($exception->redirectTo() ?? route('login')); } private function handleExceptions($request, $exception) { if ($exception instanceof NotFoundHttpException) { // ajax 404 json feedback if ($request->ajax()) { return response()->json(['error' => 'Not Found'], 404); } flash(trans('errors.body.page_not_found'))->error()->important(); // normal 404 view page feedback return redirect() ->back() ->withErrors(['msg', trans('errors.body.page_not_found')]); } if ($exception instanceof ModelNotFoundException) { // ajax 404 json feedback if ($request->ajax()) { return response()->json(['error' => 'Not Found'], 404); } // normal 404 view page feedback return response()->view('errors.404', [], 404); } if ($exception instanceof FatalThrowableError) { // ajax 500 json feedback if ($request->ajax()) { return response()->json(['error' => 'Error Page'], 500); } // normal 500 view page feedback return response()->view('errors.500', [], 500); } return parent::render($request, $exception); } }