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

    • <bdo id='znTh2'></bdo><ul id='znTh2'></ul>

  • <tfoot id='znTh2'></tfoot>
  • <small id='znTh2'></small><noframes id='znTh2'>

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

        如何使 Laravel 的 Validator $rules 成為可選?

        How to make Laravel#39;s Validator $rules optional?(如何使 Laravel 的 Validator $rules 成為可選?)
        • <i id='VvuCS'><tr id='VvuCS'><dt id='VvuCS'><q id='VvuCS'><span id='VvuCS'><b id='VvuCS'><form id='VvuCS'><ins id='VvuCS'></ins><ul id='VvuCS'></ul><sub id='VvuCS'></sub></form><legend id='VvuCS'></legend><bdo id='VvuCS'><pre id='VvuCS'><center id='VvuCS'></center></pre></bdo></b><th id='VvuCS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='VvuCS'><tfoot id='VvuCS'></tfoot><dl id='VvuCS'><fieldset id='VvuCS'></fieldset></dl></div>

          <small id='VvuCS'></small><noframes id='VvuCS'>

        • <legend id='VvuCS'><style id='VvuCS'><dir id='VvuCS'><q id='VvuCS'></q></dir></style></legend>

            <tfoot id='VvuCS'></tfoot>
              <bdo id='VvuCS'></bdo><ul id='VvuCS'></ul>

                    <tbody id='VvuCS'></tbody>

                  本文介紹了如何使 Laravel 的 Validator $rules 成為可選?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  假設(shè)我有兩種方法的 User 模型:

                  Let's say I have User model with two methods:

                  User.php

                  class User extends Eloquent
                  {  
                      /* Validation rules */
                      private static $rules = array(
                          'user'  => 'unique:users|required|alpha_num',
                          'email' => 'required|email'
                      );
                  
                      /* Validate against registration form */
                      public static function register($data)
                      {
                          $validator = Validator::make($data, static::$rules);
                          if($validator->fails())
                          {
                              /*... do someting */
                          }
                          else
                          {
                              /* .. do something else */
                          }
                      }
                  
                      /* Validate against update form */
                      public static function update($data)
                      {
                          $validator = Validator::make($data, static::$rules);
                          if($validator->fails())
                          {
                              /*... do someting */
                          }
                          else
                          {
                              /* .. do something else */
                          }
                      }
                  }
                  

                  我的問題:我怎樣才能讓驗證規(guī)則成為可選的,所以即使 update() 的數(shù)據(jù)只是 email 字段,它會忽略 user 并仍然驗證為 true.
                  這是可能的還是我遺漏了什么?

                  My question: How can I make validation rules optional, so even if data for update() would be just email field, it would ignore user and still validate to true.
                  Is this even possible or am I missing something?

                  抱歉我的英語不好.

                  推薦答案

                  不確定我的問題是否正確,但如果用戶是可選的,則應(yīng)從驗證器中刪除必需".這樣你將有:

                  Not sure if I'm getting your question right but if the user is optional you should remove 'required' from the validator. This way you will have:

                  'user'  => 'unique:users|alpha_num',
                  

                  代替:

                  'user'  => 'unique:users|required|alpha_num',
                  

                  另一方面,我為我的模型創(chuàng)建了一個自定義方法,該方法能夠根據(jù)傳入?yún)?shù)返回自定義驗證規(guī)則.

                  On the other hand I create a custom method for my models that is able to return custom validation rules depending on incoming parameters.

                  例如:

                  private function getValidationRules($rules)
                  {
                      if ($rules == UPDATE_EMAIL)
                      {
                          return array('email' => 'required|email');
                      } else {
                          return array(
                              'user'  => 'unique:users|required|alpha_num',
                              'email' => 'required|email'
                          );
                      }
                  }
                  

                  我想這只是個人選擇,但我發(fā)現(xiàn)從方法中獲取驗證規(guī)則可以更好地控制我真正想要驗證的內(nèi)容,尤其是當(dāng)您想要執(zhí)行一些高級驗證時.

                  I guess it's only a personal choice, but I have found that getting the validation rules from a method allows more control over what I really want to validate, especially when you want to perform some advanced validations.

                  希望對你有幫助.

                  這篇關(guān)于如何使 Laravel 的 Validator $rules 成為可選?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

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

                        <tbody id='mH8pc'></tbody>

                            <small id='mH8pc'></small><noframes id='mH8pc'>

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

                            主站蜘蛛池模板: 国际精品鲁一鲁一区二区小说 | 日韩av美女电影 | 国产精品美女www爽爽爽 | 一级aaaaaa毛片免费同男同女 | 亚洲www | 在线观看免费福利 | 精品国产精品三级精品av网址 | 在线三级网址 | av不卡一区 | 日本一区二区三区精品视频 | 热re99久久精品国产99热 | 成人免费视频一区二区 | 激情免费视频 | 国产精品久久国产精品99 gif | 日本黄色不卡视频 | 一区二区日本 | 亚洲永久免费 | 国产伦精品一区二区三区四区视频 | 成人av片在线观看 | 国产欧美精品一区二区色综合朱莉 | 久久香焦 | 日韩专区中文字幕 | 免费99视频 | 国产精品1 | 国产精品我不卡 | 成人高清视频在线观看 | 久久黄色精品视频 | 荷兰欧美一级毛片 | 久久久人成影片一区二区三区 | 国产激情一区二区三区 | 国产乱人伦精品一区二区 | 欧美精品一区二区三区在线四季 | 久久国产精品久久国产精品 | 91秦先生艺校小琴 | 亚洲精品视频观看 | 91社区在线观看播放 | 成人av网站在线观看 | av在线天堂 | 美美女高清毛片视频免费观看 | 精品人伦一区二区三区蜜桃网站 | 亚洲一二三在线 |