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

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

      2. <legend id='tFPdQ'><style id='tFPdQ'><dir id='tFPdQ'><q id='tFPdQ'></q></dir></style></legend>

      3. <small id='tFPdQ'></small><noframes id='tFPdQ'>

        Laravel (HasMany) 不檢索值

        Laravel (HasMany) doesnt rectrieve values(Laravel (HasMany) 不檢索值)

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

            <tbody id='PCymM'></tbody>
          <legend id='PCymM'><style id='PCymM'><dir id='PCymM'><q id='PCymM'></q></dir></style></legend>

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

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

                  本文介紹了Laravel (HasMany) 不檢索值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有以下型號:

                      namespace App;
                  
                  use IlluminateDatabaseEloquentModel;
                  
                  class forum_category extends Model
                  {
                      //
                  
                      protected $table = 'forum_category';
                  
                      public function posts()
                      {
                          $this->hasMany('Appforum_post');
                      }
                  }
                  

                  namespace App;
                  
                  use IlluminateDatabaseEloquentModel;
                  
                  class forum_post extends Model
                  {
                      //
                      protected $table = 'forum_post';
                  
                  
                      public function category()
                      {
                          $this->belongsTo('Appforum_category');
                      }
                  }
                  

                  在我的控制器中,我嘗試使用他們的帖子獲取所有類別:

                  in my controller i attempt to get all categories with their posts:

                      namespace AppHttpControllers;
                  
                  use IlluminateHttpRequest;
                  use IlluminateRoutingController;
                  
                  use Appforum_category as forum_category;
                  
                  
                  class ForumController extends Controller
                  {
                  
                      public function __construct()
                      {
                  
                      }
                  
                      public function index ()
                      {
                  
                          $categories = forum_category::all();
                  
                          return view('forum', ['categories' => $categories]);
                      }
                  
                      public function createPost()
                      {
                  
                      }
                  
                      public function createReply()
                      {
                  
                      }
                  }
                  

                  但是它似乎只返回我的類別.

                  However it seems to only be returning my categories.

                  誰能告訴我我做錯了什么?

                  Can someone tell me what ive done wrong?

                  推薦答案

                  查詢應如下所示:

                  $categories = forum_category::with('posts')->get();
                  

                  https://laravel.com/docs/5.5/eloquent-relationships#eager-loading

                  如果您在 forum_post 表中有 category_id,這將加載具有相關帖子的類別.

                  If you have category_id in the forum_post table, this will load categories with related posts.

                  然后只需遍歷集合以獲取帖子:

                  Then just iterate over the collection to get posts:

                  @foreach ($categories as $category)
                      @foreach ($category->posts as $post)
                          {{ $post->title }}
                      @endforeach
                  @endforeach
                  

                  另外,關系應該是:

                  public function category()
                  {
                      return $this->belongsTo('Appforum_category');
                  }
                  

                  這篇關于Laravel (HasMany) 不檢索值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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的訪問被拒絕)

                    <tbody id='HVZJn'></tbody>
                  <i id='HVZJn'><tr id='HVZJn'><dt id='HVZJn'><q id='HVZJn'><span id='HVZJn'><b id='HVZJn'><form id='HVZJn'><ins id='HVZJn'></ins><ul id='HVZJn'></ul><sub id='HVZJn'></sub></form><legend id='HVZJn'></legend><bdo id='HVZJn'><pre id='HVZJn'><center id='HVZJn'></center></pre></bdo></b><th id='HVZJn'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='HVZJn'><tfoot id='HVZJn'></tfoot><dl id='HVZJn'><fieldset id='HVZJn'></fieldset></dl></div>
                      <bdo id='HVZJn'></bdo><ul id='HVZJn'></ul>
                    • <small id='HVZJn'></small><noframes id='HVZJn'>

                      1. <legend id='HVZJn'><style id='HVZJn'><dir id='HVZJn'><q id='HVZJn'></q></dir></style></legend>

                        <tfoot id='HVZJn'></tfoot>

                          • 主站蜘蛛池模板: 浴室洗澡偷拍一区二区 | 岛国av免费在线观看 | 日韩在线精品 | 国产视频在线一区二区 | 91免费看片 | 一区二区精品 | 亚洲九色| 蜜臀网站 | 九九热国产视频 | 久久9精品 | 高清国产午夜精品久久久久久 | 日韩精品一区二区三区在线播放 | 成人免费视频网站在线观看 | 成人免费在线视频 | 亚州中文字幕 | 亚洲国产一区二区三区在线观看 | 久婷婷 | 狠狠伊人| 日本在线免费观看 | 久久精品一区二区 | 国产四虎| 日韩精品一区二 | 欧美极品少妇xxxxⅹ免费视频 | 国产精品视频播放 | 操操日 | 99久久99久久精品国产片果冰 | 精品日韩一区 | www.国产视频| 日韩精品一区二区三区视频播放 | 91久久久久久 | 久久久久综合 | 91视频国产一区 | 91在线电影| 亚洲精品一区二区三区中文字幕 | 精品欧美一区二区精品久久 | 免费黄视频网站 | 色眯眯视频在线观看 | 欧美日韩一区二区三区四区五区 | 超碰人人插 | 伊人网在线综合 | 精品欧美一区二区三区久久久 |