*/ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; protected $dontReport = [ BaseException::class, ]; /** * Register the exception handling callbacks for the application. */ public function register(): void { $this->renderable(function (NotFoundHttpException $e, Request $request) { if ($this->shouldReturnJson($request, $e)) { return response()->json(['status' => 1, 'msg' => '资源不存在', 'data' => '']); } }); $this->renderable(function (BaseException $e, Request $request) { if ($this->shouldReturnJson($request, $e)) { return response()->json(['status' => $e->getCode(), 'msg' => $e->getMessage(), 'data' => '']); } }); } protected function unauthenticated($request, AuthenticationException $exception) { return $this->shouldReturnJson($request, $exception) ? response()->json(['status' => 401, 'msg' => $exception->getMessage(), 'data' => '']) : redirect()->guest($exception->redirectTo() ?? route('login')); } protected function invalidJson($request, ValidationException $exception) { return response()->json([ 'status' => 422, 'msg' => str_replace(' (and 1 more error)', '', $exception->getMessage()), 'errors' => $exception->errors(), 'data' => '', ], 200); } }