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

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

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

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

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

      Eloquent Laravel 模型上的 __construct

      A __construct on an Eloquent Laravel Model(Eloquent Laravel 模型上的 __construct)

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

          • <bdo id='tobEH'></bdo><ul id='tobEH'></ul>
          • <tfoot id='tobEH'></tfoot>

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

                  <tbody id='tobEH'></tbody>

                <legend id='tobEH'><style id='tobEH'><dir id='tobEH'><q id='tobEH'></q></dir></style></legend>
              • 本文介紹了Eloquent Laravel 模型上的 __construct的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我有一個自定義的 setter,我在我的模型的 __construct 方法中運行它.

                I have a custom setter that I'm running in a __construct method on my model.

                這是我要設置的屬性.

                    protected $directory;
                

                我的構造函數

                    public function __construct()
                    {
                        $this->directory = $this->setDirectory();
                    }
                

                二傳手:

                    public function setDirectory()
                    {
                        if(!is_null($this->student_id)){
                            return $this->student_id;
                        }else{
                            return 'applicant_' . $this->applicant_id;
                        }
                    }
                

                我的問題是在我的 setter 中,$this->student_id(這是從數據庫中提取的模型的一個屬性)返回 null.當我在我的 setter 中 dd($this) 時,我注意到我的 #attributes:[] 是一個空數組.
                所以,直到 __construct() 被觸發后,模型的屬性才會被設置.如何在構造方法中設置 $directory 屬性?

                My problem is that inside my setter the, $this->student_id (which is an attribute of the model being pulled from the database) is returning null. When I dd($this) from inside my setter, I notice that my #attributes:[] is an empty array.
                So, a model's attributes aren't set until after __construct() is fired. How can I set my $directory attribute in my construct method?

                推薦答案

                您需要將構造函數更改為:

                You need to change your constructor to:

                public function __construct(array $attributes = array())
                {
                    parent::__construct($attributes);
                
                    $this->directory = $this->setDirectory();
                }
                

                第一行 (parent::__construct()) 會在你的代碼運行之前運行 Eloquent Model 自己的構造方法,這將設置所有的屬性為你.此外,對構造函數方法簽名的更改是繼續支持 Laravel 期望的用法: $model = new Post(['id' => 5, 'title' => 'My Post']);

                The first line (parent::__construct()) will run the Eloquent Model's own construct method before your code runs, which will set up all the attributes for you. Also the change to the constructor's method signature is to continue supporting the usage that Laravel expects: $model = new Post(['id' => 5, 'title' => 'My Post']);

                經驗法則實際上是始終記住,在擴展類時,要檢查您沒有覆蓋現有方法以使其不再運行(這對于神奇的 __construct__get 等方法).您可以檢查原始文件的來源,看看它是否包含您正在定義的方法.

                The rule of thumb really is to always remember, when extending a class, to check that you're not overriding an existing method so that it no longer runs (this is especially important with the magic __construct, __get, etc. methods). You can check the source of the original file to see if it includes the method you're defining.

                這篇關于Eloquent Laravel 模型上的 __construct的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                相關文檔推薦

                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 和魔術方法)
                php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                <tfoot id='n9f5q'></tfoot>
              • <i id='n9f5q'><tr id='n9f5q'><dt id='n9f5q'><q id='n9f5q'><span id='n9f5q'><b id='n9f5q'><form id='n9f5q'><ins id='n9f5q'></ins><ul id='n9f5q'></ul><sub id='n9f5q'></sub></form><legend id='n9f5q'></legend><bdo id='n9f5q'><pre id='n9f5q'><center id='n9f5q'></center></pre></bdo></b><th id='n9f5q'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='n9f5q'><tfoot id='n9f5q'></tfoot><dl id='n9f5q'><fieldset id='n9f5q'></fieldset></dl></div>

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

                  <bdo id='n9f5q'></bdo><ul id='n9f5q'></ul>
                      <tbody id='n9f5q'></tbody>
                    <legend id='n9f5q'><style id='n9f5q'><dir id='n9f5q'><q id='n9f5q'></q></dir></style></legend>

                          主站蜘蛛池模板: 日韩一区二区久久 | 午夜免费影视 | 国产电影一区二区 | 国产高清在线 | 91在线精品秘密一区二区 | 久久精点视频 | 亚洲成人av在线播放 | 18成人在线观看 | 亚洲欧洲在线观看视频 | 欧美国产日韩在线观看 | 91视频网 | 国产高清免费 | 欧美色综合天天久久综合精品 | 亚洲午夜一区二区 | 日韩免费福利视频 | 久久久国产一区二区三区四区小说 | 91.色| 久久精品国产一区二区三区 | 成人福利网站 | 国产操操操 | 欧美精品成人一区二区三区四区 | 国产真实乱全部视频 | 一区在线播放 | 亚洲天堂一区 | 国产福利91精品一区二区三区 | 日韩第一区 | 国产精品久久久久一区二区三区 | 亚洲成人免费观看 | 免费观看一级特黄欧美大片 | 中文字幕一区二区三区在线观看 | avmans最新导航地址 | 成人精品久久日伦片大全免费 | 成年视频在线观看福利资源 | 日本a网站| 91精品久久久久 | 色偷偷人人澡人人爽人人模 | 国产日韩欧美在线观看 | 午夜国产一级 | 久久曰视频 | 久久久久久久久综合 | 国产成在线观看免费视频 |