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

<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="qwawimqqmiuu" 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 參數

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

          <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="qwawimqqmiuu" 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 參數的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個表存儲,存儲有很多庫,在庫中我有存儲store_id的外鍵.

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

                  存儲表

                  id(PK)
                  

                  圖書館表

                  id(PK)
                  store_id(FK)
                  

                  我對 hasManybelongsTo 參數感到困惑,包括在 docs 它說

                  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 來自哪個表?和belongsTo一樣,foreign_key和other_key是從哪個表來的?

                  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');
                  }
                  

                  圖書館模型

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

                  因為有時候我把一個表的主鍵id改成sid這樣的其他名字,所以我總是想指定哪個是外鍵和主鍵

                  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

                  推薦答案

                  為了簡化語法,想到了 return $this->hasMany('AppComment', 'foreign_key', 'local_key'); 參數為:

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

                  1. 您要鏈接到的模型
                  2. 鏈接回當前表的 id 列的外部表(您要鏈接到的表)的列(除非您指定了第三個參數,在這種情況下它將使用那個)
                  3. 應該使用的當前表的列 - 即如果您不希望其他表的外鍵鏈接到當前表的 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

                  在您的情況下,因為您在 libraries 表中使用了 store_id,您的生活變得輕松了.在您的 Store 模型中定義時,以下內容應該可以完美運行:

                  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 會自動將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');
                  }
                  

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

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

                  相關文檔推薦

                  Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死鎖異常代碼?)
                  PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滾動游標不起作用)
                  PHP PDO ODBC connection(PHP PDO ODBC 連接)
                  Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔術方法)
                  php pdo get only one value from mysql; value that equals to variable(php pdo 只從 mysql 獲取一個值;等于變量的值)
                  MSSQL PDO could not find driver(MSSQL PDO 找不到驅動程序)
                    <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="qwawimqqmiuu" 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'>

                            主站蜘蛛池模板: 中文字幕乱码亚洲精品一区 | 又爽又黄axxx片免费观看 | 羞羞视频在线观看网站 | 中国一级毛片免费 | 久久久久久国产精品免费免费 | 免费在线国产视频 | 中文字幕在线观看一区 | 日日干日日色 | 日韩激情在线 | 草b视频 | 中文字幕一区二区三区精彩视频 | 做a的各种视频 | 日本三级网 | 福利网址 | 久久国产综合 | 日韩精品一区二区三区在线播放 | 精品久久久久久久久久久久久久久久久 | 日本免费一区二区三区 | 国产精华一区 | 97av视频在线观看 | 中文字幕不卡在线观看 | 91久久久精品国产一区二区蜜臀 | 国产精品1区2区3区 中文字幕一区二区三区四区 | 国精产品一区一区三区免费完 | 久久综合av | 欧美在线一区二区三区 | 99精品久久久国产一区二区三 | 国产小视频在线看 | 日本在线一区二区 | 色在线看 | 亚洲精品免费看 | 国产农村妇女毛片精品久久麻豆 | 日本精品久久 | 亚洲影音 | 亚洲欧洲色视频 | 久久国产成人午夜av影院武则天 | 中文字幕 在线观看 | 亚洲第一区国产精品 | 殴美成人在线视频 | 午夜资源 | 丝袜一区二区三区 |