fullUrl() . ",请求IP:" . $request->getClientIp()); return parent::render($request, $exception); } // 捕获身份校验异常 if ($exception instanceof AuthenticationException) { if ($request->ajax()) { return response()->json(['status' => 'fail', 'data' => '', 'message' => 'Unauthorized']); } else { return response()->view('error.404'); } } // 捕获CSRF异常 if ($exception instanceof TokenMismatchException) { if ($request->ajax()) { return response()->json(['status' => 'fail', 'data' => '', 'message' => trans('404.csrf_title')]); } else { return response()->view('error.csrf'); } } return response()->view('error.404'); } /** * 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); } return redirect()->guest(route('login')); } }