<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 功能強大 支持多語言、二開方便! 廣告
                當然,如果每一次需要驗證的時候都手動的建立并且驗證 Validator 實例會非常的麻煩。不用擔心,你有其他的選擇!Laravel自帶的 `App\Http\Controllers\Controller` 基類使用了一個 `ValidatesRequests `的 `trait`。這個 `trait `提供了一個單一的、便捷的方法來驗證 HTTP 請求。代碼如下: ~~~ /** * Store the incoming blog post. * * @param Request $request * @return Response */ public function store(Request $request) { $this->validate($request, [ 'title' => 'required|unique|max:255', 'body' => 'required', ]); // } ~~~ 如果驗證通過了,你的代碼會正常繼續執行。如果驗證失敗,那么會拋出一個 `Illuminate\Contracts\Validation\ValidationException` 異常。這個異常會被自動捕獲,然后重定向至用戶上一個頁面。而錯誤信息甚至已經存儲至 session 中! 如果收到的是一個 AJAX 請求,那么不會生成一個重定向。相反的,一個帶有 422 狀態碼的 HTTP 響應會被返回給瀏覽器,包含了一個含有錯誤信息的 JSON 對象。 比如,如下是手動創建驗證的等效寫法: ~~~ /** * Store the incoming blog post. * * @param Request $request * @return Response */ public function store(Request $request) { $v = Validator::make($request->all(), [ 'title' => 'required|unique|max:255', 'body' => 'required', ]); if ($v->fails()) { return redirect()->back()->withErrors($v->errors()); } // } ~~~ ## 自定義閃存后的錯誤格式 如果你想要自定義驗證失敗后已經閃存至 session 的錯誤消息格式,可以通過覆蓋基類控制器的 `formatValidationErrors`。不要忘記在文件頂部引入 `Illuminate\Validation\Validator` 類。 ~~~ /** * {@inheritdoc} */ protected function formatValidationErrors(Validator $validator) { return $validator->errors()->all(); } ~~~
                  <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>

                              哎呀哎呀视频在线观看