Answer the question
In order to leave comments, you need to log in
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>
<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>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question