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

<legend id='L6oQC'><style id='L6oQC'><dir id='L6oQC'><q id='L6oQC'></q></dir></style></legend>

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

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

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

      1. laravel eloquent 嵌套評論和回復

        laravel eloquent nested comment and replies(laravel eloquent 嵌套評論和回復)
      2. <legend id='sCAZJ'><style id='sCAZJ'><dir id='sCAZJ'><q id='sCAZJ'></q></dir></style></legend>

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

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

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

                  <tbody id='sCAZJ'></tbody>
                1. 本文介紹了laravel eloquent 嵌套評論和回復的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  幾天前,我看到一個網站,用戶可以在其中評論帖子.其他用戶可以回復.并且重播可以有像下面的示例截圖一樣的回復..

                  Few days ago, I saw a website where users can comment on a post. Other users can reply on that. and a replay can have replies like the example screenshot below..

                  所以我想試一試,但不知何故無法弄清楚.這是我的數據庫設置

                  So I thought to give it a try but somehow couldnt figure it out. here is my database set up

                  Schema::create('comments', function (Blueprint $table) {
                              $table->increments('id');
                              $table->unsignedInteger('user_id');
                              $table->unsignedInteger('post_id');
                              $table->unsignedInteger('reply_id')->default(0);
                              $table->text('body');
                              $table->timestamps();
                          });
                  

                  模型中的關系

                  class Comment extends Model
                  {
                      protected $fillable = [
                          'user_id',
                          'post_id',
                          'reply_id',
                          'body'
                      ];
                  
                      public function user()
                      {
                          return $this->belongsTo(User::class);
                      }
                  
                      public function post()
                      {
                          return $this->belongsTo(Post::class);
                      }
                  
                      public function replies()
                      {
                          return $this->hasMany(Comment::class,'reply_id','id');
                      }
                  

                  在控制器中

                  $comments = Comment::with('replies')->where('reply_id','=',0)->get(['id','reply_id','body']);
                     return response($comments);
                  

                  這完美地返回了評論和回復.但是如果有reply的回復,就不會顯示了.我怎樣才能做到這一點?需要建議.

                  this perfectly returns the comment and replies. But if there is a reply of reply, it doesnt show up. How can I do that? Need suggestion.

                  推薦答案

                  reply_idnullable() parent_id 交換.所以基本上你想知道評論是否有父級.

                  Swap reply_id with a nullable() parent_id. So basically you want to know if a comment has a parent.

                  然后在Comment模型中,添加一個self關系來獲取所有parent_id匹配的評論.

                  Then in Comment model, add a self relationship to take all comments whose parent_id match.

                  public function replies() {
                      return $this->hasMany('AppComment', 'parent_id');
                  }
                  

                  在您的視圖中,您可以為每個評論及其回復嵌套循環

                  In your view you can have nested loops for each comments and its replies

                  @foreach($comments as $comment) 
                     {{ $comment->content }}
                  
                     @if ( $comment->replies )
                         @foreach($comment->replies as $rep1)
                             {{ $rep1->content }}
                             ...
                         @endforeach
                     @endif
                  @endforeach
                  

                  這篇關于laravel eloquent 嵌套評論和回復的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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的訪問被拒絕)
                    <bdo id='SCsFX'></bdo><ul id='SCsFX'></ul>

                        • <small id='SCsFX'></small><noframes id='SCsFX'>

                          <legend id='SCsFX'><style id='SCsFX'><dir id='SCsFX'><q id='SCsFX'></q></dir></style></legend>

                          <tfoot id='SCsFX'></tfoot>

                              <tbody id='SCsFX'></tbody>
                          1. <i id='SCsFX'><tr id='SCsFX'><dt id='SCsFX'><q id='SCsFX'><span id='SCsFX'><b id='SCsFX'><form id='SCsFX'><ins id='SCsFX'></ins><ul id='SCsFX'></ul><sub id='SCsFX'></sub></form><legend id='SCsFX'></legend><bdo id='SCsFX'><pre id='SCsFX'><center id='SCsFX'></center></pre></bdo></b><th id='SCsFX'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='SCsFX'><tfoot id='SCsFX'></tfoot><dl id='SCsFX'><fieldset id='SCsFX'></fieldset></dl></div>
                          2. 主站蜘蛛池模板: 国产精品久久久久久久久图文区 | 围产精品久久久久久久 | 九九99靖品 | 日韩影音| 精品国产一区二区三区日日嗨 | 国产超碰人人爽人人做人人爱 | 成人性视频免费网站 | 欧美日本一区二区 | 男人的天堂久久 | 欧美久久精品一级黑人c片 91免费在线视频 | 亚洲 欧美 精品 | 欧美成人在线网站 | 有码一区 | 视频一区二区国产 | 国产精品99久久久久久久久久久久 | 久久精品久久久 | 中文字幕在线不卡播放 | 91国产在线视频在线 | 91视频观看 | 在线观看成人精品 | 亚洲视频在线一区 | 不卡在线视频 | 久久亚洲美女 | 日日久 | 一区二区精品 | 波多野结衣二区 | 黄色在线免费看 | 91久久国产精品 | 久久久精品 | 精品久久久久久久久久 | 精品国产欧美 | 国产亚洲成av人在线观看导航 | 999久久久久久久久6666 | 亚洲精品在线视频 | 国产精品免费一区二区三区 | 日韩中文一区二区三区 | 国产一区二区欧美 | 免费高清av | 精品亚洲91 | 日日爱夜夜操 | 一级做a爰片性色毛片视频停止 |