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
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community