Support the ongoing development of Laravel.io →
Views Packages
Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.