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

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

    1. <small id='Hl8dS'></small><noframes id='Hl8dS'>

      <tfoot id='Hl8dS'></tfoot>

    2. <legend id='Hl8dS'><style id='Hl8dS'><dir id='Hl8dS'><q id='Hl8dS'></q></dir></style></legend>
      • <bdo id='Hl8dS'></bdo><ul id='Hl8dS'></ul>

        Laravel 屬于不工作

        Laravel belongsTo not working(Laravel 屬于不工作)
          <bdo id='XoeYG'></bdo><ul id='XoeYG'></ul>

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

            1. <small id='XoeYG'></small><noframes id='XoeYG'>

              <i id='XoeYG'><tr id='XoeYG'><dt id='XoeYG'><q id='XoeYG'><span id='XoeYG'><b id='XoeYG'><form id='XoeYG'><ins id='XoeYG'></ins><ul id='XoeYG'></ul><sub id='XoeYG'></sub></form><legend id='XoeYG'></legend><bdo id='XoeYG'><pre id='XoeYG'><center id='XoeYG'></center></pre></bdo></b><th id='XoeYG'></th></span></q></dt></tr></i><div class="z3kccfu" id='XoeYG'><tfoot id='XoeYG'></tfoot><dl id='XoeYG'><fieldset id='XoeYG'></fieldset></dl></div>
                <tbody id='XoeYG'></tbody>
                <tfoot id='XoeYG'></tfoot>
                  本文介紹了Laravel 屬于不工作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我的應用中有 2 個模型,用戶"和'MedicineType'(每個用戶屬于一個 MedicineType).

                  I have 2 models in my app, 'User' & 'MedicineType' (each User belongs to one MedicineType).

                  我使用belongsTo() 和hasMany() 在兩個模型之間建立了一對多關系.hasMany() 關系完美運行,但belongTo() 不起作用.有誰知道我哪里出錯了?

                  I made the one-to-many relation between two model using belongsTo() and hasMany(). hasMany() relation works perfectly but belongTo() doesn't work. Does anyone know where did I make a mistake?

                  User::find(1)->medicine_type [這不返回任何內容]

                  User::find(1)->medicine_type [this returns nothing]

                  MedicineType::find(1)->users [返回用戶]

                  MedicineType::find(1)->users [this returns users]

                  這是模型的代碼:

                  class MedicineType extends Eloquent {
                  
                      public function users()
                      {
                          return $this->hasMany('User');
                      }
                  }
                  
                  
                  class User extends Eloquent {
                  
                      public function medicine_type()
                      {
                          return $this->belongsTo('MedicineType');
                      }
                  }
                  

                  這是我的數據庫結構:

                  users:
                      id
                      name
                      medicine_type_id 
                  
                  medicine_types:
                      id
                      name
                  

                  推薦答案

                  你的關系不工作的原因不是因為模型中指定的關系,而是因為 User 模型中的方法命名而不是指定外部鍵.

                  The reason your relation is not working is not because of the relations specified in the model, but because of the method naming in the User model and not specifying the foreign key.

                  代替:

                  public function medicine_type()
                  {
                      return $this->belongsTo('MedicineType');
                  }
                  

                  使用:

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

                  我希望這對你有用;)

                  一切都在一起:

                  <?php // app/models/MedicineType.php
                  
                  class MedicineType extends Eloquent {
                  
                     // Determines which database table to use
                     protected $table = 'medicine_types';
                  
                     public function users() 
                     {
                        return $this->hasMany('User');
                     }
                  
                  }
                  

                  和:

                  <?php // app/models/User.php
                  
                  class User extends Eloquent {
                  
                     // Determines which database table to use
                     protected $table = 'users';
                  
                     public function medicineType() 
                     {
                        return $this->belongsTo('MedicineType', 'id');
                     }
                  
                  }
                  

                  測試它是否有效:

                  $user = User::find(1);
                  return $user->medicineType->name;
                  

                  這成功返回了相關的medicine_type 的名稱.

                  This successfully returns the related medicine_type's name.

                  我希望這能幫助你進一步;)

                  I hope this helps you further ;)

                  這篇關于Laravel 屬于不工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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的訪問被拒絕)
                      <tfoot id='CENls'></tfoot>
                      <legend id='CENls'><style id='CENls'><dir id='CENls'><q id='CENls'></q></dir></style></legend>
                        <bdo id='CENls'></bdo><ul id='CENls'></ul>

                            <tbody id='CENls'></tbody>

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

                          <i id='CENls'><tr id='CENls'><dt id='CENls'><q id='CENls'><span id='CENls'><b id='CENls'><form id='CENls'><ins id='CENls'></ins><ul id='CENls'></ul><sub id='CENls'></sub></form><legend id='CENls'></legend><bdo id='CENls'><pre id='CENls'><center id='CENls'></center></pre></bdo></b><th id='CENls'></th></span></q></dt></tr></i><div class="iqyga83" id='CENls'><tfoot id='CENls'></tfoot><dl id='CENls'><fieldset id='CENls'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: 金属回收_废铜废铁回收_边角料回收_废不锈钢回收_废旧电缆线回收-广东益夫金属回收公司 | 防水套管厂家_刚性防水套管_柔性防水套管_不锈钢防水套管-郑州中泰管道 | 南京精锋制刀有限公司-纵剪机刀片_滚剪机刀片_合金刀片厂家 | 本安接线盒-本安电路用接线盒-本安分线盒-矿用电话接线盒-JHH生产厂家-宁波龙亿电子科技有限公司 | 包塑丝_高铁绑丝_地暖绑丝_涂塑丝_塑料皮铁丝_河北创筹金属丝网制品有限公司 | 解放卡车|出口|济南重汽|报价大全|山东三维商贸有限公司 | 武汉宣传片制作-视频拍摄-企业宣传片公司-武汉红年影视 | 青岛美佳乐清洁工程有限公司|青岛油烟管道清洗|酒店|企事业单位|学校工厂厨房|青岛油烟管道清洗 插针变压器-家用电器变压器-工业空调变压器-CD型电抗器-余姚市中驰电器有限公司 | 胀套-锁紧盘-风电锁紧盘-蛇形联轴器「厂家」-瑞安市宝德隆机械配件有限公司 | CE认证_FCC认证_CCC认证_MFI认证_UN38.3认证-微测检测 CNAS实验室 | 定制异形重型钢格栅板/钢格板_定做踏步板/排水沟盖板_钢格栅板批发厂家-河北圣墨金属制品有限公司 | 糖衣机,除尘式糖衣机,全自动糖衣机,泰州市长江制药机械有限公司 体感VRAR全息沉浸式3D投影多媒体展厅展会游戏互动-万展互动 | 深圳市人通智能科技有限公司| 灰板纸、灰底白、硬纸板等纸品生产商-金泊纸业 | 房间温控器|LonWorks|海思| 权威废金属|废塑料|废纸|废铜|废钢价格|再生资源回收行情报价中心-中废网 | 网带通过式抛丸机,,网带式打砂机,吊钩式,抛丸机,中山抛丸机生产厂家,江门抛丸机,佛山吊钩式,东莞抛丸机,中山市泰达自动化设备有限公司 | 福建自考_福建自学考试网 | 服务器之家 - 专注于服务器技术及软件下载分享 | 天津云仓-天津仓储物流-天津云仓一件代发-顺东云仓 | 工业机械三维动画制作 环保设备原理三维演示动画 自动化装配产线三维动画制作公司-南京燃动数字 聚合氯化铝_喷雾聚氯化铝_聚合氯化铝铁厂家_郑州亿升化工有限公司 | 郑州爱婴幼师学校_专业幼师培训_托育师培训_幼儿教育培训学校 | 底部填充胶_电子封装胶_芯片封装胶_芯片底部填充胶厂家-东莞汉思新材料 | 防爆电机生产厂家,YBK3电动机,YBX3系列防爆电机,YBX4节防爆电机--河南省南洋防爆电机有限公司 | 餐饮小吃技术培训-火锅串串香培训「何小胖培训」_成都点石成金[官网] | 超声波电磁流量计-液位计-孔板流量计-料位计-江苏信仪自动化仪表有限公司 | 低温柔性试验仪-土工布淤堵-沥青车辙试验仪-莱博特(天津)试验机有限公司 | 济南网站建设|济南建网站|济南网站建设公司【济南腾飞网络】【荐】 | 东莞海恒试验仪器设备有限公司 | 西安中国国际旅行社(西安国旅) | 深圳装修_店面装修设计_餐厅设计_装修全包价格-尚泰装饰设计 | 桨叶搅拌机_螺旋挤压/方盒旋切造粒机厂家-无锡市鸿诚输送机械有限公司 | 苏州注册公司_苏州代理记账_苏州工商注册_苏州代办公司-恒佳财税 | 闪蒸干燥机-喷雾干燥机-带式干燥机-桨叶干燥机-[常州佳一干燥设备] | 档案密集柜_手动密集柜_智能密集柜_内蒙古档案密集柜-盛隆柜业内蒙古密集柜直销中心 | 河南空气能热水器-洛阳空气能采暖-洛阳太阳能热水工程-洛阳润达高科空气能商行 | 油罐车_加油机_加油卷盘_加油机卷盘_罐车人孔盖_各类球阀_海底阀等车用配件厂家-湖北华特专用设备有限公司 | 【星耀裂变】_企微SCRM_任务宝_视频号分销裂变_企业微信裂变增长_私域流量_裂变营销 | atcc网站,sigma试剂价格,肿瘤细胞现货,人结肠癌细胞株购买-南京科佰生物 | 单锥双螺旋混合机_双螺旋锥形混合机-无锡新洋设备科技有限公司 | 污水处理设备,一体化泵站,一体化净水设备-「梦之洁环保设备厂家」 |