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

<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="qwawimqqmiuu" 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="qwawimqqmiuu" id='XoeYG'><tfoot id='XoeYG'></tfoot><dl id='XoeYG'><fieldset id='XoeYG'></fieldset></dl></div>
                <tbody id='XoeYG'></tbody>
                <tfoot id='XoeYG'></tfoot>
                  本文介紹了Laravel 屬于不工作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

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

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

                  我使用belongsTo() 和hasMany() 在兩個模型之間建立了一對多關(guān)系.hasMany() 關(guān)系完美運(yùn)行,但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 [這不返回任何內(nèi)容]

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

                  這是我的數(shù)據(jù)庫結(jié)構(gòu):

                  users:
                      id
                      name
                      medicine_type_id 
                  
                  medicine_types:
                      id
                      name
                  

                  推薦答案

                  你的關(guān)系不工作的原因不是因為模型中指定的關(guān)系,而是因為 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;
                  

                  這成功返回了相關(guān)的medicine_type 的名稱.

                  This successfully returns the related medicine_type's name.

                  我希望這能幫助你進(jìn)一步;)

                  I hope this helps you further ;)

                  這篇關(guān)于Laravel 屬于不工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  MySQLi prepared statement amp; foreach loop(MySQLi準(zhǔn)備好的語句amp;foreach 循環(huán))
                  Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是從整個服務(wù)器還是從同一用戶獲取記錄?)
                  PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 無法識別登錄信息)
                  mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 個參數(shù))
                  Php mysql pdo query: fill up variable with query result(Php mysql pdo 查詢:用查詢結(jié)果填充變量)
                  MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用戶“root@“l(fā)ocalhost的訪問被拒絕)
                      <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="qwawimqqmiuu" id='CENls'><tfoot id='CENls'></tfoot><dl id='CENls'><fieldset id='CENls'></fieldset></dl></div>
                          1. 主站蜘蛛池模板: av影音资源| 欧美一区免费 | 精品99在线 | 天天综合国产 | 大陆一级毛片免费视频观看 | 91精品国产综合久久婷婷香蕉 | 久久久久亚洲 | 欧美日韩一区二区三区四区五区 | 日本国产精品视频 | 久久国产亚洲精品 | 久久久久久免费毛片精品 | 男人av的天堂 | 久久精品视频99 | 欧美视频在线免费 | 久久69精品久久久久久久电影好 | 国产一区二区三区四区 | 久久91| 久久成人精品视频 | 亚洲午夜精品一区二区三区他趣 | 欧美日韩在线成人 | 成人水多啪啪片 | 午夜免费| 国产黄色麻豆视频 | 国产精品1区2区3区 中文字幕一区二区三区四区 | 91精品国产91久久久久久 | 久久久久国产精品一区三寸 | 国产日韩在线观看一区 | 午夜免费视频 | 成人在线视频一区 | 欧美精品网站 | 亚洲一区中文字幕 | 99精品久久久 | 亚洲精品99| 午夜私人影院在线观看 | 国产三级电影网站 | 成人在线免费视频 | 亚洲aⅴ | 精品美女视频在免费观看 | 91亚洲精选 | 81精品国产乱码久久久久久 | 国产视频观看 |