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

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

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

          <bdo id='Wtwzv'></bdo><ul id='Wtwzv'></ul>
      1. 在 Laravel 4 的 Eloquent 中使用樞軸模型數據作為與

        Using pivot model data as a relationship to another model in Laravel 4#39;s Eloquent(在 Laravel 4 的 Eloquent 中使用樞軸模型數據作為與另一個模型的關系)

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

        1. <tfoot id='B2dbB'></tfoot>

                <bdo id='B2dbB'></bdo><ul id='B2dbB'></ul>
                • <i id='B2dbB'><tr id='B2dbB'><dt id='B2dbB'><q id='B2dbB'><span id='B2dbB'><b id='B2dbB'><form id='B2dbB'><ins id='B2dbB'></ins><ul id='B2dbB'></ul><sub id='B2dbB'></sub></form><legend id='B2dbB'></legend><bdo id='B2dbB'><pre id='B2dbB'><center id='B2dbB'></center></pre></bdo></b><th id='B2dbB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='B2dbB'><tfoot id='B2dbB'></tfoot><dl id='B2dbB'><fieldset id='B2dbB'></fieldset></dl></div>
                    <tbody id='B2dbB'></tbody>
                  <legend id='B2dbB'><style id='B2dbB'><dir id='B2dbB'><q id='B2dbB'></q></dir></style></legend>
                  本文介紹了在 Laravel 4 的 Eloquent 中使用樞軸模型數據作為與另一個模型的關系的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個用于多對多關系的數據透視表,其中包括另一個模型的第三個索引參數.我希望能夠使用 Eloquent 訪問此模型.

                  I have a pivot table for a many to many relationship which includes a third index parameter for another model. I would like to be able to use Eloquent to access this model.

                  在我的應用程序中,我有一個 User,他可以擁有許多 Subjects 和許多 Semesters.當用戶擁有 Subject 時,它也需要屬于給定的 Semester.我有一個 userssubjectssemesters 表,以及一個 subject_user 表(其中有 user_idsubject_idsemester_id).

                  In my application, I have a User who can have many Subjects and many Semesters. When a user has a Subject, it needs to belong to a given Semester as well. I have a users, subjects and semesters table, as well as a subject_user table (which has user_id, subject_id and semester_id).

                  當我檢索 User 的主題時,我還希望能夠獲得 Subject 已連接到的 Session通過數據透視表.

                  When I retrieve the User's subjects, I would also like to be able to get the Session the Subject has been connected to through the pivot table.

                  class User
                  {
                      public function subjects()
                      {
                          $this->belongsToMany('Subject')->withPivot('session_id');
                      }
                  }
                  

                  我希望能夠做的如下,并讓我可以使用 Session 模型.

                  What I would like to be able to do is as follows, and have the Session model available to me.

                  $user->subjects()->pivot->semester;
                  

                  這樣的事情是可能的,還是需要對 Eloquent 進行擴展?

                  Is such a thing possible, or will this require an extension to Eloquent?

                  推薦答案

                  有一種方法可以通過創建一個擴展 IlluminateDatabaseEloquentRelationsPivot 的類來實現.盡管這種方法還需要向擁有此數據透視表的兩個模型添加一些代碼,以便它們在需要時使用新的數據透視表.

                  There is a way to do this by creating a class that extends IlluminateDatabaseEloquentRelationsPivot. Though this approach also requires adding some code to the two models that own this pivot so that they use the new Pivot when needed.

                  此鏈接討論自定義樞軸模型的實現:https://github.com/laravel/framework/issues/2093#issuecomment-39154456

                  This link discusses the implementation of the Custom Pivot Model: https://github.com/laravel/framework/issues/2093#issuecomment-39154456

                  use IlluminateDatabaseEloquentRelationsPivot;
                  
                  class SubjectUser extends Pivot {
                     // add your relationships back to User and Subject
                      public function session() {
                           // your relation to session here
                      }
                  }
                  
                  class Subject extends Eloquent {
                      ...
                      public function newPivot(Eloquent $parent, array $attributes, $table, $exists) {
                          if ($parent instanceof User) {
                              return new SubjectUser($parent, $attributes, $table, $exists);
                          }
                          return parent::newPivot($parent, $attributes, $table, $exists);
                      }
                  }
                  
                  class User extends Eloquent {
                      ...
                      public function newPivot(Eloquent $parent, array $attributes, $table, $exists) {
                          if ($parent instanceof Subject) {
                              return new SubjectUser($parent, $attributes, $table, $exists);
                          }
                          return parent::newPivot($parent, $attributes, $table, $exists);
                      }
                  }
                  

                  現在您將可以訪問已定義的樞軸關系.

                  Now you will have access to that pivot's relationship that have been defined.

                  $user->subjects->first()->pivot->session->...
                  

                  注意:您不會直接與該課程互動.當這兩個模型之間需要樞軸時,會創建它而不是默認的樞軸.

                  Note: You will not be interacting with this class directly. It is created instead of the default Pivot when the pivot is needed between those 2 models.

                  Laravel 文檔參考:使用數據透視表 有一小段關于定義自定義樞軸模型.

                  Laravel Doc Reference: Working with Pivot Tables has a short passage about Defining a Custom Pivot Model.

                  這篇關于在 Laravel 4 的 Eloquent 中使用樞軸模型數據作為與另一個模型的關系的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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的訪問被拒絕)

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

                          <tbody id='jsCOZ'></tbody>

                        <legend id='jsCOZ'><style id='jsCOZ'><dir id='jsCOZ'><q id='jsCOZ'></q></dir></style></legend><tfoot id='jsCOZ'></tfoot>

                          1. 主站蜘蛛池模板: 亚洲www啪成人一区二区 | 欧美成人免费在线 | 在线观看成年视频 | 精品综合久久 | 91超碰在线观看 | www.久| 免费不卡av | 91精品国产92| 国产亚洲区 | 亚洲免费观看视频网站 | 日韩中文字幕在线观看 | 久久精品色欧美aⅴ一区二区 | 日韩视频在线观看 | 亚洲高清久久 | 一区二区三区网站 | 久久久女| 美女一级黄 | 国产精品亚洲一区二区三区在线观看 | 99在线观看视频 | 国产亚洲精品一区二区三区 | 欧美激情久久久 | 在线成人免费视频 | 亚洲一区高清 | 久久精品中文 | 色综合天天天天做夜夜夜夜做 | 国产精品a级 | 亚洲精品成人av | 久久久av| 久久精品免费观看 | 国产精品视频在线播放 | 久久久精品综合 | 台湾a级理论片在线观看 | 午夜av影院 | av免费网站在线观看 | 色综合九九 | 午夜影院视频在线观看 | 色毛片| 亚洲国产精品久久久久 | 在线播放亚洲 | 草草视频在线观看 | 免费av观看|