2

On Laravel 5.2, I'm trying to put two menus (X latest contents, and the same for a specific user) on near every page.

The lazy way would be to generate those arrays in each of the controllers, but is there a way to generate it when the templating system needs them ?

For instance, my template could call something like {{ $menu }} and the menu would be generated only when this was present ?

Marc Brillault
  • 1,902
  • 4
  • 21
  • 41

1 Answers1

3

Laravel has a feature called view composer ,which lets you do some actions when a template file is loaded.

you could set the X latest contents into a template file and then include it wherever you want to and use view composer to fetch the data.

Gal Sisso
  • 1,939
  • 19
  • 20