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

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

  • <legend id='TkRQZ'><style id='TkRQZ'><dir id='TkRQZ'><q id='TkRQZ'></q></dir></style></legend>

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

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

        <tfoot id='TkRQZ'></tfoot>

        Laravel hasMany 和belongsTo 參數(shù)

        Laravel hasMany and belongsTo parameters(Laravel hasMany 和belongsTo 參數(shù))

          <tfoot id='kH0lT'></tfoot>

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

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

                  本文介紹了Laravel hasMany 和belongsTo 參數(shù)的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  我有一個(gè)表存儲(chǔ),存儲(chǔ)有很多庫(kù),在庫(kù)中我有存儲(chǔ)store_id的外鍵.

                  I have a table store, and store has many libraries, in library I have foreign key of store store_id.

                  存儲(chǔ)表

                  id(PK)
                  

                  圖書(shū)館表

                  id(PK)
                  store_id(FK)
                  

                  我對(duì) hasManybelongsTo 參數(shù)感到困惑,包括在 docs 它說(shuō)

                  I'm confused with hasMany and belongsTo parameters include, in the docs it says

                  return $this->hasMany('AppComment', 'foreign_key');

                  return $this->hasMany('AppComment', 'foreign_key');

                  return $this->hasMany('AppComment', 'foreign_key', 'local_key');

                  return $this->hasMany('AppComment', 'foreign_key', 'local_key');

                  return $this->belongsTo('AppPost', 'foreign_key', 'other_key');

                  return $this->belongsTo('AppPost', 'foreign_key', 'other_key');

                  hasMany foreign_key 和 local_key 來(lái)自哪個(gè)表?和belongsTo一樣,foreign_key和other_key是從哪個(gè)表來(lái)的?

                  Which table of hasMany foreign_key and local_key came from? Same with belongsTo which table of foreign_key and other_key came from?

                  店鋪模式

                  public function library(){
                      return $this->hasMany('AppLibrary', 'what_foreign_key_should_be_here','what_other_key_should_be_here');
                  }
                  

                  圖書(shū)館模型

                  public function stores(){
                      return $this->belongsTo('AppStores', 'what_foreign_key_should_be_here', 'what_other_key_should_be_here');
                  }
                  

                  因?yàn)橛袝r(shí)候我把一個(gè)表的主鍵id改成sid這樣的其他名字,所以我總是想指定哪個(gè)是外鍵和主鍵

                  Because sometimes I change my primary key id of a table to other name like sid, so I always want to specify which is foreign key and primary key

                  推薦答案

                  為了簡(jiǎn)化語(yǔ)法,想到了 return $this->hasMany('AppComment', 'foreign_key', 'local_key'); 參數(shù)為:

                  To simplify the syntax, think of the return $this->hasMany('AppComment', 'foreign_key', 'local_key'); parameters as:

                  1. 您要鏈接到的模型
                  2. 鏈接回當(dāng)前表的 id 列的外部表(您要鏈接到的表)的列(除非您指定了第三個(gè)參數(shù),在這種情況下它將使用那個(gè))
                  3. 應(yīng)該使用的當(dāng)前表的列 - 即如果您不希望其他表的外鍵鏈接到當(dāng)前表的 id
                  1. The model you want to link to
                  2. The column of the foreign table (the table you are linking to) that links back to the id column of the current table (unless you are specifying the third parameter, in which case it will use that)
                  3. The column of the current table that should be used - i.e if you don't want the foreign key of the other table to link to the id column of the current table

                  在您的情況下,因?yàn)槟?libraries 表中使用了 store_id,您的生活變得輕松了.在您的 Store 模型中定義時(shí),以下內(nèi)容應(yīng)該可以完美運(yùn)行:

                  In your circumstance, because you have used store_id in the libraries table, you've made life easy for yourself. The below should work perfectly when defined in your Store model:

                  public function libraries()
                  {
                      return $this->hasMany('AppLibrary');
                  }
                  

                  在幕后,Laravel 會(huì)自動(dòng)將Store 表的id 列鏈接到Library<的store_id 列/code> 表格.

                  Behind the scenes, Laravel will automatically link the id column of the Store table to the store_id column of the Library table.

                  如果你想明確定義它,那么你可以這樣做:

                  If you wanted to explicitly define it, then you would do it like this:

                  public function libraries(){
                      return $this->hasMany('AppLibrary', 'store_id','id');
                  }
                  

                  • 模型標(biāo)準(zhǔn)是單數(shù)命名的函數(shù)返回一個(gè)belongsTo,而復(fù)數(shù)函數(shù)返回一個(gè)hasMany(即$store->libraries() 或$library->store()).
                  • 這篇關(guān)于Laravel hasMany 和belongsTo 參數(shù)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動(dòng)游標(biāo)不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術(shù)方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個(gè)值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅(qū)動(dòng)程序)
                    <tbody id='PApDg'></tbody>

                    <bdo id='PApDg'></bdo><ul id='PApDg'></ul>

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

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

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

                            主站蜘蛛池模板: 苹果售后维修点查询,苹果iPhone授权售后维修服务中心 – 修果网 拼装地板,悬浮地板厂家,悬浮式拼装运动地板-石家庄博超地板科技有限公司 | 全自动定氮仪-半自动凯氏定氮仪厂家-祎鸿仪器 | 上海律师咨询_上海法律在线咨询免费_找对口律师上策法网-策法网 广东高华家具-公寓床|学生宿舍双层铁床厂家【质保十年】 | 尚为传动-专业高精密蜗轮蜗杆,双导程蜗轮蜗杆,蜗轮蜗杆减速机,蜗杆减速机生产厂家 | hdpe土工膜-防渗膜-复合土工膜-长丝土工布价格-厂家直销「恒阳新材料」-山东恒阳新材料有限公司 ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | 厦门网站建设_厦门网站设计_小程序开发_网站制作公司【麦格科技】 | 医学模型生产厂家-显微手术模拟训练器-仿真手术模拟训练系统-北京医教科技 | 外贮压-柜式-悬挂式-七氟丙烷-灭火器-灭火系统-药剂-价格-厂家-IG541-混合气体-贮压-非贮压-超细干粉-自动-灭火装置-气体灭火设备-探火管灭火厂家-东莞汇建消防科技有限公司 | 东莞工厂厂房装修_无尘车间施工_钢结构工程安装-广东集景建筑装饰设计工程有限公司 | 耐高温风管_耐高温软管_食品级软管_吸尘管_钢丝软管_卫生级软管_塑料波纹管-东莞市鑫翔宇软管有限公司 | 滚筒烘干机_转筒烘干机_滚筒干燥机_转筒干燥机_回转烘干机_回转干燥机-设备生产厂家 | 立式_复合式_壁挂式智能化电伴热洗眼器-上海达傲洗眼器生产厂家 理化生实验室设备,吊装实验室设备,顶装实验室设备,实验室成套设备厂家,校园功能室设备,智慧书法教室方案 - 东莞市惠森教学设备有限公司 | 塑料瓶罐_食品塑料瓶_保健品塑料瓶_调味品塑料瓶–东莞市富慷塑料制品有限公司 | 合肥汽车充电桩_安徽充电桩_电动交流充电桩厂家_安徽科帝新能源科技有限公司 | 我爱古诗词_古诗词名句赏析学习平台| 直读光谱仪,光谱分析仪,手持式光谱仪,碳硫分析仪,创想仪器官网 | 成都中天自动化控制技术有限公司 | 自清洗过滤器_全自动过滤器_全自动反冲洗过滤器_量子过滤器-滑漮滴 | 拉伸膜,PE缠绕膜,打包带,封箱胶带,包装膜厂家-东莞宏展包装 | 国产离子色谱仪,红外分光测油仪,自动烟尘烟气测试仪-青岛埃仑通用科技有限公司 | 赛尔特智能移动阳光房-阳光房厂家-赛尔特建筑科技(广东)有限公司 | pH污水传感器电极,溶解氧电极传感器-上海科蓝仪表科技有限公司 | 大鼠骨髓内皮祖细胞-小鼠神经元-无锡欣润生物科技有限公司 | 胶水,胶粘剂,AB胶,环氧胶,UV胶水,高温胶,快干胶,密封胶,结构胶,电子胶,厌氧胶,高温胶水,电子胶水-东莞聚力-聚厉胶粘 | pbootcms网站模板|织梦模板|网站源码|jquery建站特效-html5模板网 | 膜结构车棚|上海膜结构车棚|上海车棚厂家|上海膜结构公司 | 酒吧霸屏软件_酒吧霸屏系统,酒吧微上墙,夜场霸屏软件,酒吧点歌软件,酒吧互动游戏,酒吧大屏幕软件系统下载 | 逗网红-抖音网红-快手网红-各大平台网红物品导航 | 在线浊度仪_悬浮物污泥浓度计_超声波泥位计_污泥界面仪_泥水界面仪-无锡蓝拓仪表科技有限公司 | 下水道疏通_管道疏通_马桶疏通_附近疏通电话- 立刻通 | 隐形纱窗|防护纱窗|金刚网防盗纱窗|韦柏纱窗|上海青木装潢制品有限公司|纱窗国标起草单位 | 滁州高低温冲击试验箱厂家_安徽高低温试验箱价格|安徽希尔伯特 | 专业甜品培训学校_广东糖水培训_奶茶培训_特色小吃培训_广州烘趣甜品培训机构 | 铁艺,仿竹,竹节,护栏,围栏,篱笆,栅栏,栏杆,护栏网,网围栏,厂家 - 河北稳重金属丝网制品有限公司 山东太阳能路灯厂家-庭院灯生产厂家-济南晟启灯饰有限公司 | 圣才学习网-考研考证学习平台,提供万种考研考证电子书、题库、视频课程等考试资料 | 宝鸡市人民医院| X光检测仪_食品金属异物检测机_X射线检测设备_微现检测 | 深圳市八百通智能技术有限公司官方网站| 广东泵阀展|阀门展-广东国际泵管阀展览会 | 集装箱展厅-住人集装箱住宿|建筑|房屋|集装箱售楼处-山东锐嘉科技工程有限公司 | 搪玻璃冷凝器_厂家-越宏化工设备 |