I have a few side bars which are being included in my blade view via @include('sidebar-1').
I'm wondering what the best approach would be when populating these sidebars with data from the database? I wont need them on every page & I have not had to deal with anything like this, I tend to pass data through the routes or the controller but I don't have a route for the side bar ^^
Any guidance is appreciated! I think the answer may be something along the lines of refactoring the way I'm including these sidebars.
Cheers
I think View Composers are what you need:
https://laravel.com/docs/5.1/views#view-composers
View composers are callbacks or class methods that are called when a view is rendered. If you have data that you want to be bound to a view each time that view is rendered, a view composer can help you organize that logic into a single location.
I use view composers for the exact situation you describe. When a particular sidebar view is rendered, Laravel automatically calls the view composer that prepares the data for that sidebar.