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

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

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

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

        <tfoot id='hQV5r'></tfoot>

      1. 如何為 Laravel/Eloquent 模型設(shè)置默認屬性值?

        How to set a default attribute value for a Laravel / Eloquent model?(如何為 Laravel/Eloquent 模型設(shè)置默認屬性值?)

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

          <tfoot id='Unixb'></tfoot>
            <tbody id='Unixb'></tbody>

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

                <legend id='Unixb'><style id='Unixb'><dir id='Unixb'><q id='Unixb'></q></dir></style></legend>

                  <bdo id='Unixb'></bdo><ul id='Unixb'></ul>

                  本文介紹了如何為 Laravel/Eloquent 模型設(shè)置默認屬性值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  如果我嘗試聲明一個屬性,如下所示:

                  public $quantity = 9;

                  ...它不起作用,因為它不被視為屬性",而只是模型類的屬性.不僅如此,我還阻止了對實際真實存在的數(shù)量"屬性的訪問.

                  那我該怎么辦?

                  解決方案

                  這就是我現(xiàn)在正在做的:

                  protected $defaults = array('數(shù)量' =>9、);公共函數(shù) __construct(array $attributes = array()){$this->setRawAttributes($this->defaults, true);parent::__construct($attributes);}

                  我建議將此作為 PR,因此我們不需要在每個模型中都聲明此構(gòu)造函數(shù),并且只需在我們的模型中聲明 $defaults 數(shù)組即可輕松應(yīng)用...<小時>

                  更新:

                  正如 cmfolio 所指出的,實際的答案很簡單:

                  只需覆蓋 $attributes 屬性即可!像這樣:

                  protected $attributes = array('數(shù)量' =>9、);

                  在此處討論了該問題.

                  If I try declaring a property, like this:

                  public $quantity = 9;
                  

                  ...it doesn't work, because it is not considered an "attribute", but merely a property of the model class. Not only this, but also I am blocking access to the actually real and existent "quantity" attribute.

                  What should I do, then?

                  解決方案

                  This is what I'm doing now:

                  protected $defaults = array(
                     'quantity' => 9,
                  );
                  
                  public function __construct(array $attributes = array())
                  {
                      $this->setRawAttributes($this->defaults, true);
                      parent::__construct($attributes);
                  }
                  

                  I will suggest this as a PR so we don't need to declare this constructor at every Model, and can easily apply by simply declaring the $defaults array in our models...


                  UPDATE:

                  As pointed by cmfolio, the actual ANSWER is quite simple:

                  Just override the $attributes property! Like this:

                  protected $attributes = array(
                     'quantity' => 9,
                  );
                  

                  The issue was discussed here.

                  這篇關(guān)于如何為 Laravel/Eloquent 模型設(shè)置默認屬性值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動程序)

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

                  <legend id='qFaD2'><style id='qFaD2'><dir id='qFaD2'><q id='qFaD2'></q></dir></style></legend>

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

                        • <bdo id='qFaD2'></bdo><ul id='qFaD2'></ul>
                            <tbody id='qFaD2'></tbody>
                          1. 主站蜘蛛池模板: 国产精品久久久久久久久久久久 | 日韩视频在线免费观看 | 欧美二区三区 | 欧美在线精品一区 | 国内精品久久久久久久影视简单 | 天天综合天天 | 亚洲毛片在线观看 | 国产一区2区 | 三级欧美 | 国产精品国产三级国产aⅴ入口 | 免费看黄色小视频 | 男人天堂99| 爱爱爱av| 伊人精品在线 | 男女激情网 | 欧美成人精品激情在线观看 | 欧美久久久久 | 亚洲成av人片在线观看无码 | 日韩在线视频免费观看 | 日韩免费视频一区二区 | 日韩欧美在 | 久久人人国产 | 6080亚洲精品一区二区 | 欧美国产精品 | 久草免费在线视频 | 中文成人无字幕乱码精品 | 国产一区二区日韩 | 91免费观看国产 | 国产精品久久久 | 日韩在线免费视频 | 亚洲女优在线播放 | 久久久久久中文字幕 | 精品熟人一区二区三区四区 | 精品成人佐山爱一区二区 | 成人视屏在线观看 | 精品国产第一区二区三区 | 日韩在线视频一区二区三区 | 欧美久久久久久 | 午夜影院黄| 精品久久一区 | 精品国产乱码久久久久久闺蜜 |