<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                ## 原因 在新某項目開發中遇到一個問題:laravel 的驗證方法會自動處理驗證響應 比如登錄方法: ~~~ $request->validate([ 'name' => 'required|array', 'password' => 'required|string', ]); ~~~ 驗證失敗時響應: status 422 ~~~ { "message": "The given data was invalid.", "errors": { "username": [ "The username field is required." ], "password": [ "The password field is required." ] } } ~~~ 我用的是ajax請求,所以我需要的是200請求的 json 錯誤信息 * 當時和前端商議自定義 status 就是在http body 的json 中加一個code狀態,每次響應都是http 200 * 查閱資料后發現只要在 Exceptions 添加對應 exception 的處理方法就ok了 ### 修改方法: * 修改文件:app/Exceptions/Hander.php * 在這個文件中添加 render 方法重寫父類的 render ~~~ /** * @param $request * @param Throwable $exception * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response * @throws Throwable */ public function render($request, Throwable $exception) { if($request->ajax() || $request->wantsJson()){ $result = [ "code"=>422, "msg"=>array_values($exception->errors())[0][0], "data"=>"" ]; return response()->json($result); } return parent::render($request, $exception); } ~~~ 就OK了
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看