title: Laravel and infinity categories as a tree
body: <p>how to display all categories, with sub, sub, sub (..) category, I have simple table:</p>
  
  <p><a href="https://i.stack.imgur.com/2SM4i.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2SM4i.jpg" alt="enter image description here"></a></p>
  
  <p>and my model:</p>
  
  <pre><code>class Category extends Model
  {
      public $fillable = [
          'parent_id',
          'name',
          'description'
      ];
  
      public function parent()
      {
          return $this-&gt;belongsTo(Category::class, 'parent_id', 'id');
      }
  
      public function children()
      {
          return $this-&gt;hasMany(Category::class, 'parent_id', 'id');
      }
  }
  </code></pre>
  
  <p>I want to get:</p>
  
  <pre><code>&lt;ul&gt;
    &lt;li&gt;Category
      &lt;ul&gt;
        &lt;li&gt;Category 1.1&lt;/li&gt;
        &lt;li&gt;Category 1.2&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/li&gt;
    (...)
  &lt;/ul&gt;
  </code></pre>