*/ protected $dontFlash = [ 'current_password', 'password', 'password_confirmation', ]; /** * Register the exception handling callbacks for the application. */ public function register(): void { $this->reportable(function (Throwable $e) { // }); } public function render($request, Throwable $e){ // // FirstOrFail 和 FindOrFail 异常处理 if ($e instanceof ModelNotFoundException) { if ($request->ajax() || $request->wantsJson()) { return response()->json(['data'=>null,'code'=>404 , 'message' => '数据未找到,或已被删除' ], 404); } }elseif($e instanceof AuthenticationException){ if ($request->ajax() || $request->wantsJson()) { return response()->json(['data'=>null,'code'=>401 , 'message' => '无效凭证,请先登录' ], 401); } }elseif ($e instanceof NotFoundHttpException) { return response()->json(['data'=>null,'code'=>404 , 'message' => '页面不存在' ], 404); } } }