久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    1. <small id='qd5ba'></small><noframes id='qd5ba'>

    2. <tfoot id='qd5ba'></tfoot>
      <legend id='qd5ba'><style id='qd5ba'><dir id='qd5ba'><q id='qd5ba'></q></dir></style></legend>
      <i id='qd5ba'><tr id='qd5ba'><dt id='qd5ba'><q id='qd5ba'><span id='qd5ba'><b id='qd5ba'><form id='qd5ba'><ins id='qd5ba'></ins><ul id='qd5ba'></ul><sub id='qd5ba'></sub></form><legend id='qd5ba'></legend><bdo id='qd5ba'><pre id='qd5ba'><center id='qd5ba'></center></pre></bdo></b><th id='qd5ba'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='qd5ba'><tfoot id='qd5ba'></tfoot><dl id='qd5ba'><fieldset id='qd5ba'></fieldset></dl></div>

        • <bdo id='qd5ba'></bdo><ul id='qd5ba'></ul>
      1. 如何在 Laravel 中手動返回或拋出驗證錯誤/異常

        How can I manually return or throw a validation error/exception in Laravel?(如何在 Laravel 中手動返回或拋出驗證錯誤/異常?)

            • <small id='pceYi'></small><noframes id='pceYi'>

                <bdo id='pceYi'></bdo><ul id='pceYi'></ul>
                <tfoot id='pceYi'></tfoot>
                <i id='pceYi'><tr id='pceYi'><dt id='pceYi'><q id='pceYi'><span id='pceYi'><b id='pceYi'><form id='pceYi'><ins id='pceYi'></ins><ul id='pceYi'></ul><sub id='pceYi'></sub></form><legend id='pceYi'></legend><bdo id='pceYi'><pre id='pceYi'><center id='pceYi'></center></pre></bdo></b><th id='pceYi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='pceYi'><tfoot id='pceYi'></tfoot><dl id='pceYi'><fieldset id='pceYi'></fieldset></dl></div>
                  <tbody id='pceYi'></tbody>
              • <legend id='pceYi'><style id='pceYi'><dir id='pceYi'><q id='pceYi'></q></dir></style></legend>
                  本文介紹了如何在 Laravel 中手動返回或拋出驗證錯誤/異常?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  有一種將 CSV 數據導入數據庫的方法.我使用

                  Have a method that's importing CSV-data into a Database. I do some basic validation using

                  class CsvImportController extends Controller
                  {
                      public function import(Request $request)
                      {   
                          $this->validate($request, [
                              'csv_file' => 'required|mimes:csv,txt',
                          ]);
                  

                  但在那之后,由于更復雜的原因,事情可能會出錯,更深入的兔子洞,會引發某種異常.我無法在這里編寫與 validate 方法一起使用的正確驗證內容,但是,我真的很喜歡 Laravel 在驗證失敗時的工作方式以及將錯誤嵌入到刀片中是多么容易查看等,所以...

                  But after that things can go wrong for more complex reasons, further down the rabbit hole, that throws exceptions of some sort. I can't write proper validation stuff to use with the validate method here, but, I really like how Laravel works when the validation fails and how easy it is to embed the error(s) into the blade view etc, so...

                  是否有一種(最好是干凈的)方法可以手動告訴 Laravel我知道我現在沒有使用你的 validate 方法,但我真的很喜歡你像我一樣在這里公開這個錯誤"?有什么我可以返回的東西,一個可以用來包裝東西的例外,或者什么?

                  Is there a (preferably clean) way to manually tell Laravel that "I know I didn't use your validate method right now, but I'd really like you to expose this error here as if I did"? Is there something I can return, an exception I can wrap things with, or something?

                  try
                  {
                      // Call the rabbit hole of an import method
                  }
                  catch(Exception $e)
                  {
                      // Can I return/throw something that to Laravel looks 
                      // like a validation error and acts accordingly here?
                  }
                  

                  推薦答案

                  從 laravel 5.5 開始,ValidationException 類有一個靜態方法 withMessages 您可以使用:

                  As of laravel 5.5, the ValidationException class has a static method withMessages that you can use:

                  $error = IlluminateValidationValidationException::withMessages([
                     'field_name_1' => ['Validation Message #1'],
                     'field_name_2' => ['Validation Message #2'],
                  ]);
                  throw $error;
                  

                  我還沒有測試過這個,但它應該可以工作.

                  I haven't tested this, but it should work.

                  更新

                  消息不必包裝在數組中.你也可以這樣做:

                  The message does not have to be wrapped in an array. You can also do:

                  use IlluminateValidationValidationException;
                  
                  throw ValidationException::withMessages(['field_name' => 'This value is incorrect']);
                  

                  這篇關于如何在 Laravel 中手動返回或拋出驗證錯誤/異常?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準備好的語句amp;foreach 循環)
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數)
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“localhost的訪問被拒絕)
                1. <small id='fVBV1'></small><noframes id='fVBV1'>

                  <tfoot id='fVBV1'></tfoot>
                  <i id='fVBV1'><tr id='fVBV1'><dt id='fVBV1'><q id='fVBV1'><span id='fVBV1'><b id='fVBV1'><form id='fVBV1'><ins id='fVBV1'></ins><ul id='fVBV1'></ul><sub id='fVBV1'></sub></form><legend id='fVBV1'></legend><bdo id='fVBV1'><pre id='fVBV1'><center id='fVBV1'></center></pre></bdo></b><th id='fVBV1'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='fVBV1'><tfoot id='fVBV1'></tfoot><dl id='fVBV1'><fieldset id='fVBV1'></fieldset></dl></div>

                        <tbody id='fVBV1'></tbody>
                    1. <legend id='fVBV1'><style id='fVBV1'><dir id='fVBV1'><q id='fVBV1'></q></dir></style></legend>
                        <bdo id='fVBV1'></bdo><ul id='fVBV1'></ul>

                          • 主站蜘蛛池模板: 夜久久 | 日本三级电影免费观看 | 粉嫩在线 | 国产亚洲欧美在线 | 日韩一 | 日韩高清一区二区 | 国产精品国产a级 | 久久九九免费 | 欧美激情精品久久久久久 | 九九热免费视频在线观看 | 91素人| 午夜寂寞影院在线观看 | 在线成人免费观看 | 91国产精品| 日韩国产欧美 | 毛片免费观看 | 青春草91| 久久在看| 激情免费视频 | 亚洲精选一区 | 亚洲第一av | 91国内精品久久 | 不卡一二区 | 日韩欧美在线一区二区 | a国产一区二区免费入口 | 亚洲夜射 | 国产精品免费观看 | 久久精品国产免费一区二区三区 | 日韩一区二区在线视频 | 日韩中文字幕av | 黄色片视频网站 | 国产一区二区在线免费观看 | 成人午夜影院 | 在线一区二区三区 | av在线一区二区三区 | 中文字幕在线观看 | 这里精品| 美女国内精品自产拍在线播放 | 成人av在线大片 | 九色视频网站 | 日韩免费视频一区二区 |