title: Laravel get all parents of category
body: <p>I have categories and subcategories in laravel</p>
  
  <pre><code>namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Category extends Model
  {
      protected $table = 'categories';
  
      public function parent()
      {
          return $this-&gt;belongsTo('App\Category', 'parent_id');
      }
  
      public function children()
      {
          return $this-&gt;hasMany('App\Category', 'parent_id');
      }
  }
  </code></pre>
  
  <p>And I can add a new category which belongs to an already created category. Something like "Test -> subcategory of test" and then let's say I will create "sub-subcategory of test" which belongs to subcategory of test which will look like this: "Test -> subcategory of test -> sub-subcategory of test"
  And in the view I want to print the parents of the category if it has any.
  I do it like this:</p>
  
  <pre><code>@if($category-&gt;parent)
     &lt;td&gt;{{ $category-&gt;parent-&gt;name }} &lt;strong&gt;-&gt;&lt;/strong&gt; {{ $category-&gt;name }}&lt;/td&gt;
  @else
     &lt;td&gt;{{ $category-&gt;name }}&lt;/td&gt;    
  @endif
  </code></pre>
  
  <p>But this only shows one parent category ("subcategory of test -> sub-subcategori of test"). I want to show all the parents which will look like this: "Test->subcategory of test -> sub-subcategory of test"
  How can I do that?</p>