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

  • <tfoot id='Aqf4O'></tfoot>

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

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

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

        Laravel 獲取與其屬性同名的 Eloquent 關(guān)系

        Laravel get Eloquent relation by same name as its attribute(Laravel 獲取與其屬性同名的 Eloquent 關(guān)系)

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

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

          2. <legend id='Kg2W4'><style id='Kg2W4'><dir id='Kg2W4'><q id='Kg2W4'></q></dir></style></legend>

                  <bdo id='Kg2W4'></bdo><ul id='Kg2W4'></ul>
                • 本文介紹了Laravel 獲取與其屬性同名的 Eloquent 關(guān)系的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有這樣的數(shù)據(jù)庫表:

                  shoot: id, name, programme
                  programme: id, name
                  

                  拍攝中的雄辯關(guān)系是這樣定義的:

                  The eloquent relationship in the shoot is defined like this:

                  public function programme() {
                      return $this->belongsTo('AppProgramme', 'programme', 'id');
                  }
                  

                  使用 dd() 時,我可以看到這是正常工作的:

                  When using dd(), I can see this is working correctly:

                  dd(Shoot:where('id','=',1)->with('programme')->first());
                  // prints the object with programme listed under the relationship
                  

                  但是,當(dāng)我急切加載拍攝并嘗試獲取程序?qū)ο髸r,我反而檢索了拍攝屬性程序".例如:

                  However when I eager-load the shoot and attempt to get the programme object, I retrieve the shoot attribute "programme" instead. E.g.:

                  $shoot = Shoot:where('id','=',1)->with('programme')->first();
                  echo $shoot->programme; // returns 1, not AppProgramme object.
                  

                  有沒有無需重寫大量代碼庫的解決方案?

                  Is there a solution to this without having to rewrite masses of the codebase?

                  推薦答案

                  relationshipcolumn 名稱不應(yīng)使用相同的名稱,否則您將將始終收到 column 名稱,因此嘗試編輯其中之一,我認(rèn)為這里最簡單的是 relationship 名稱:

                  You shouldn't use the same name for the both relationship and column name, else you'll receive always the column name so try to edit one of them, I think the easiest one here is the relationship name :

                  public function programmeObj() {
                      return $this->belongsTo('AppProgramme', 'programme', 'id');
                  }
                  

                  然后將其稱為:

                  echo $shoot->programmeObj;
                  

                  注意:但如果你想遵循約定,你應(yīng)該用 programme_id 替換 name 屬性,所以:

                  NOTE : But if you want to follow conventions you should replace the name attribute by programme_id so :

                  public function programme() {
                      return $this->belongsTo('AppProgramme', 'programme_id', 'id');
                  }
                  

                  希望這會有所幫助.

                  這篇關(guān)于Laravel 獲取與其屬性同名的 Eloquent 關(guān)系的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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的訪問被拒絕)

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

                    <tfoot id='8h0mz'></tfoot>

                      <small id='8h0mz'></small><noframes id='8h0mz'>

                        <tbody id='8h0mz'></tbody>
                      • <bdo id='8h0mz'></bdo><ul id='8h0mz'></ul>

                            主站蜘蛛池模板: 久久黄视频 | 91久久国产综合久久91精品网站 | 欧美日韩综合精品 | 成人欧美日韩一区二区三区 | 久久夜色精品国产 | 欧美中文字幕一区二区三区 | 精品久久久久久中文字幕 | 日韩精品一区二区三区中文字幕 | 亚洲国产精品久久人人爱 | 日日夜夜精品视频 | 国产婷婷 | 国产精品亚洲综合 | 91在线精品一区二区 | av在线免费网站 | 激情 婷婷 | 在线观看亚洲精品视频 | 密室大逃脱第六季大神版在线观看 | 亚洲精品欧美 | 国产精品免费福利 | 国产视频一视频二 | 亚洲免费在线 | 成人在线看片 | 992tv人人草 久久精品超碰 | 精品福利av导航 | 国产精品欧美日韩 | 91看片网站 | 国产精品久久久久久久粉嫩 | 福利成人 | 成人一区二| 成av在线| 又黄又色 | 欧美精品国产一区二区 | 欧美淫片 | 亚洲国产专区 | 美美女高清毛片视频免费观看 | 国产精品国产精品国产专区不蜜 | 国产一区二区三区四区三区四 | 午夜精品一区二区三区三上悠亚 | 国产精品美女久久久久久免费 | 久久久.com| 久久免费精品视频 |