In my Laravel Blade Layout I created files for the header, navigation, footer, etc.
Those Files have been @include()
d into a layout file, which has a yield('content')
.
Now, I want to show for example a product in a view. The view however uses the nav.blade.php
, which shows categories (loading from the db).
When sending my product
data to my view, I get an error, because the nav has no data about categories
:
Undefined variable: categories
Is there a possibility to give the nav the data without sending it with every view?
My public function
for the product page currently looks like this:
$product = Product::findOrFail($id);
return view('product.single')->with('product', $product);
In order to work it should also send this with it:
$categories = Category::with('subcategories.products.prices', 'subcategories.products.image')->get();
But i don't want to send that with every view.