J
J
jacko0362014-08-27 21:52:10
nested set
jacko036, 2014-08-27 21:52:10

What is the correct way to display a nested set category tree in Laravel 4?

Good afternoon!
I use the following baum add-on for multiple attachments.
In the controller I get all the categories and turn them into a tree
$categories = Category::all()->toHierarchy();
in index.blade.php

<ul style="padding-left: 10px;">
@foreach ($categories as $category)
   <li><a href="#">{{ $category->name }}</a></li>
   @if( isset( $category->children ) && count($category->children ) >1 )
      @include('categories.children', array('categories' => $category->children))
   @endif
@endforeach
</ul>

in categories/children.blade.php
<ul>
@foreach ($categories as $category)
  <li>
      <a href="#">{{ $category->name }}</a>
      @if( isset($category->children) && count($category->children ) >1 )
      @include('categories.children', array('categories' => $category->children))
      @endif
  </li>
@endforeach
</ul>

in principle, everything works with this method, but I doubt the correctness of such a conclusion of categories.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elena, 2014-08-27
@Nidora

Try to read this manual, suddenly it will help :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question