pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

<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="e60cwyq" 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="ymqyes2" 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="cu2uima" 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. 主站蜘蛛池模板: 并离网逆变器_高频UPS电源定制_户用储能光伏逆变器厂家-深圳市索克新能源 | 北京乾茂兴业科技发展有限公司 | 焦作网 WWW.JZRB.COM| 欧美日韩国产一区二区三区不_久久久久国产精品无码不卡_亚洲欧洲美洲无码精品AV_精品一区美女视频_日韩黄色性爱一级视频_日本五十路人妻斩_国产99视频免费精品是看4_亚洲中文字幕无码一二三四区_国产小萍萍挤奶喷奶水_亚洲另类精品无码在线一区 | 小型铜米机-干式铜米机-杂线全自动铜米机-河南鑫世昌机械制造有限公司 | 电伴热系统施工_仪表电伴热保温箱厂家_沃安电伴热管缆工业技术(济南)有限公司 | 苏州柯瑞德货架-仓库自动化改造解决方案 | 碳刷_刷握_集电环_恒压簧_电刷厂家-上海丹臻机电科技有限公司 | 小威小说网 - 新小威小说网 - 小威小说网小说搜索引擎 | 泥浆在线密度计厂家-防爆数字压力表-膜盒-远传压力表厂家-江苏大亚自控设备有限公司 | 二手电脑回收_二手打印机回收_二手复印机回_硒鼓墨盒回收-广州益美二手电脑回收公司 | 档案密集架_电动密集架_移动密集架_辽宁档案密集架-盛隆柜业厂家现货批发销售价格公道 | 铝箔袋,铝箔袋厂家,东莞铝箔袋,防静电铝箔袋,防静电屏蔽袋,防静电真空袋,真空袋-东莞铭晋让您的产品与众不同 | 品牌策划-品牌设计-济南之式传媒广告有限公司官网-提供品牌整合丨影视创意丨公关活动丨数字营销丨自媒体运营丨数字营销 | 立式矫直机_卧式矫直机-无锡金矫机械制造有限公司 | 钢格板|镀锌钢格板|热镀锌钢格板|格栅板|钢格板|钢格栅板|热浸锌钢格板|平台钢格板|镀锌钢格栅板|热镀锌钢格栅板|平台钢格栅板|不锈钢钢格栅板 - 专业钢格板厂家 | 北京律师事务所_房屋拆迁律师_24小时免费法律咨询_云合专业律师网 | 磁棒电感生产厂家-电感器厂家-电感定制-贴片功率电感供应商-棒形电感生产厂家-苏州谷景电子有限公司 | 实验室pH计|电导率仪|溶解氧测定仪|离子浓度计|多参数水质分析仪|pH电极-上海般特仪器有限公司 | 塑料造粒机「厂家直销」-莱州鑫瑞迪机械有限公司 | 塑胶地板-商用PVC地板-pvc地板革-安耐宝pvc塑胶地板厂家 | 分类168信息网 - 分类信息网 免费发布与查询| 粘弹体防腐胶带,聚丙烯防腐胶带-全民塑胶 | 400电话_400电话申请_888元包年_400电话办理服务中心_400VIP网 | 温州富欧金属封头-不锈钢封头厂家| 税筹星_灵活用工平台_企业财务顾问_财税法薪综合服务平台 | 直读光谱仪,光谱分析仪,手持式光谱仪,碳硫分析仪,创想仪器官网 | 压滤机滤板_厢式_隔膜_板框压滤机滤板厂家价格型号材质-大凯环保 | 派克防爆伺服电机品牌|国产防爆伺服电机|高低温伺服电机|杭州摩森机电科技有限公司 | 新中天检测有限公司青岛分公司-山东|菏泽|济南|潍坊|泰安防雷检测验收 | 环保袋,无纺布袋,无纺布打孔袋,保温袋,环保袋定制,环保袋厂家,环雅包装-十七年环保袋定制厂家 | 色油机-色母机-失重|称重式混料机-称重机-米重机-拌料机-[东莞同锐机械]精密计量科技制造商 | 招商帮-一站式网络营销服务|搜索营销推广|信息流推广|短视视频营销推广|互联网整合营销|网络推广代运营|招商帮企业招商好帮手 | 电镀标牌_电铸标牌_金属标贴_不锈钢标牌厂家_深圳市宝利丰精密科技有限公司 | 真空粉体取样阀,电动楔式闸阀,电动针型阀-耐苛尔(上海)自动化仪表有限公司 | 上海律师事务所_上海刑事律师免费咨询平台-煊宏律师事务所 | 上海单片机培训|重庆曙海培训分支机构—CortexM3+uC/OS培训班,北京linux培训,Windows驱动开发培训|上海IC版图设计,西安linux培训,北京汽车电子EMC培训,ARM培训,MTK培训,Android培训 | 预制舱-电力集装箱预制舱-模块化预制舱生产厂家-腾达电器设备 | 深圳3D打印服务-3D打印加工-手板模型加工厂-悟空打印坊 | 安徽集装箱厂-合肥国彩钢结构板房工程有限公司| 步入式高低温测试箱|海向仪器 |