久久久久久久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. 主站蜘蛛池模板: 99九九久久 | 免费一区在线观看 | 久久一热| xxxxx黄色片 欧美一区免费 | 69av片| 国产成人精品一区二区在线 | 精品在线观看一区二区 | 在线视频a| 日本黄视频在线观看 | 情侣酒店偷拍一区二区在线播放 | 免费播放一级片 | 欧美日韩精品在线免费观看 | 可以在线观看av的网站 | 性国产丰满麻豆videosex | 欧美日韩精品一区二区三区视频 | 自拍第一页 | 一区视频在线播放 | 男女视频免费 | 欧美一区二区网站 | 欧美日韩国产一区二区三区不卡 | 久久久久久免费看 | 国产精品久久久亚洲 | 亚洲自拍偷拍视频 | 亚洲成人精品一区二区 | 精品美女在线观看 | 美女人人操 | 精品国产乱码久久久久久闺蜜 | 久久综合成人精品亚洲另类欧美 | 久草视频在线播放 | 成人国产精品久久 | 二区av| 亚洲第1页 | 欧美一级在线 | 亚洲一区二区在线 | 精品国产欧美一区二区三区不卡 | 国产精品一区2区 | 日本免费视频在线观看 | 精品综合网 | 久久91精品| 欧美一区二区三区久久精品 | 午夜精品久久久久久久 |