Support the ongoing development of Laravel.io →
Blade Views
Last updated 2 years ago.
0

The Controller is used together with Routes. For the Controller you have, something like this needs to be in web.php:

Route::get('/homepage', 'NavbarController@show');

What this says is, whenever YOURSITE/homepage is accessed, the show() function in NavbarController is called. And thus, the $manufacturer variable you have there will also be available.

Now, assuming you want the navbar to be shown across all pages on the website, if you continue using your current code, you'd have to use the show() function for all Routes. That would be a lot of the same code in different files and controllers, and that's not good. Instead, have a look at some solutions presented in this discussion. Using one of the solutions in there would allow you to share the $manufacturer across all pages, from one place alone.

--

Quick tip though, rename $manufacturer to $manufacturers. And then in the foreach loop, be clearer with the variables as such:

@foreach ($manufacturers as $manufacturer)
     <li><a href="#">{{$manufacturer->name}}</a></li>
@endforeach
0

Thank you. Solved with composers.

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.