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');
You can get route parameter via Request facade:
$categoryId = Request::route('category');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community