title: Nested comments with Blade in Laravel
body: <p>I'm trying to generate nested comments with Blade in Laravel. It seems as if I have to make a blade template that has unlimited nesting comments preconfigured for each comment and it's child comments. But I want the comments to generate automatically.</p>
  
  <p>This is my Comment model:</p>
  
  <pre><code>class Comment extends Model {
  
      protected $table = 'comments';
  
      public function user()
      {
          return $this-&gt;hasOne('App\Models\User', 'id', 'user_id');
      }
  
      public function post()
      {
          return $this-&gt;hasOne('App\Models\Post', 'id', 'post_id');
      }
  
      public function children()
      {
          return $this-&gt;hasMany('App\Models\Comment', 'parent_id', 'id');
      }
  
  }
  </code></pre>
  
  <p>And in my view I'm doing</p>
  
  <pre><code>@foreach($comments as $comment)
  &lt;!-- Comment markup --&gt;
      @if($comment-&gt;children-&gt;count() &gt; 0)
          @foreach($comment-&gt;children as $child)
          &lt;!-- Child comment markup --&gt;
          @if($child-&gt;children-&gt;count() &gt; 0) // I have to do this unlimited times
              @foreach ....
  
              @endforeach
          @endif
      @endif
  @endforeach
  </code></pre>
  
  <p>I'm looking for a way to automate this, maybe with a function or something.</p>