array_first(array_collapse($exception->errors()))], 400); return showJson(102, array_first(array_collapse($exception->errors()))); } if ($exception instanceof UnauthorizedHttpException) { return response($exception->getMessage(), 401); } // 权限拦截器 if ($exception instanceof \Spatie\Permission\Exceptions\UnauthorizedException) { // 你的代码在这 ... return showJson(102, 1002, ['msg' => $exception->getMessage()]); } // 如果不被允许的路由 if ($exception instanceof MethodNotAllowedHttpException || $exception instanceof NotFoundHttpException) { if (!($request->ajax() || $request->wantsJson())) { return showJson(102, '路由不存在'); } } return parent::render($request, $exception); } }