Answer the question
In order to leave comments, you need to log in
How to pass the brand id inside the ViewComposerService provider in order to get a list of child categories based on it?
I am making a global menu and trying to display categories that belong to the brand in the menu. In my case, the brand_id is stored in the categories table. The menu is made in a separate template and is connected on the brand page and on the category page. It is not possible to pass the value of the category parent (brand_id) in the request, it works as I want if I specify the id manually. Tell me how to do it right? Through the controllers for each template, I do not want to receive a list of categories by parent.
Category model:
public function brand()
{
return $this->hasMany(Brand::class, 'brand_id');
}
public function category() {
return $this->hasMany(Category::class, 'brand_id');
}
View::composer('site.partials.sidebar', function ($view) {
$view->with('categories', Category::with('brand')->where('brand_id', 4)->get());
//выводит все категории бренда с id 4.
});
Answer the question
In order to leave comments, you need to log in
You are welcome.
View::composer('test.test', function ($view) {
dd($view->getData());
});
return view('test.test')->with([
'test_variable' => 'ололо',
]);
@include('test.test', [
'test_variable' => 'ололо',
])
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question