Hello, I managed to solve my problem, but it started to give me a headache. So here is the solution if anyone needs it: Controller:
public function getIndex(){
return View::make('categories.index')
->with('categories', Category::all());
}
EDIT: New view code for infinite nested sets,the other one was working for a single parent-child relationship
View:
<?php $counter=0; ?>
@foreach($categories as $category)
@foreach($category->getDescendantsAndSelf(array('id','parent_id','name','depth'))->toHierarchy() as $relation)
<table>
<tr>
@if($relation->depth==0)
<td>{{$relation->name}}</td>
<!-- End Check -->
@else
@for($i = 0; $i < $relation->depth; $i++)
@endfor
<td style="text-indent:{{$i+1}}em">{{$relation->name}}</td>
@endif
</tr>
<table>
This should give a pretty visualization for nested categories.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community