Support the ongoing development of Laravel.io →
posted 10 years ago
Views

Hello frineds,

I have troubles to make breadcrumbs from nestedset categories. My categories build based on https://github.com/lazychaser/laravel-nestedset

AppServiceProvider.php

view()->composer('modules.breadcrumbs', function($view, $id)
{
	$view->withTree(Category::ancestorsOf($id)->toTree());
});

modules/breadcrumbs.blade.php

@foreach ($tree as $node)  
  	@if (Request::is('/'))   Вы тута!!!

  	@else
  		@foreach ($node->children as $child)  
  		<a href="/{{ $child->sef }}">{{ $child->title }} </a>

  			@foreach ($child->children as $level2)
  			<a href="/{{ $level2->parent->sef }}/{{ $level2->sef }}">{{ $level2->title }} </a>

  					@foreach ($child->children as $level3)
  					<a href="/{{ $level3->parent->sef }}/{{ $level3->sef }}">{{ $level3->title }} </a>
  					@endforeach


  			@endforeach

  		@endforeach

  	@endif
@endforeach	

for the first test I did it like that and of course it worked with static id of node

AppServiceProvider.php

view()->composer('modules.breadcrumbs', function($view)
{
	$view->withTree(Category::ancestorsOf(28)->toTree());
});

but breadcrumbs must be dynamic and the problem is where can I get this $id from?

Normally in routes I don't use id.

Route::get('/', 'HomeController@index');

// News
Route::get('/news', 'NewsController@getIndex');
Route::get('/news/{title}', 'NewsController@getItem');

// Links
Route::get('links', 'FileController@getIndex');
Route::get('links/{category}', 'FileController@getCategory');

// FAQ
Route::get('faq', 'FAQController@getIndex');
Route::get('faq/{category}', 'FAQController@getCategory');
Route::get('faq/{category}/{item}', 'FAQController@getItem');
Last updated 3 years ago.
0

You can get route parameter via Request facade:

$categoryId = Request::route('category');
0

Sign in to participate in this thread!

Eventy

Your banner here too?

schel4ok schel4ok Joined 15 Feb 2015

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.

© 2025 Laravel.io - All rights reserved.