Laravel : having the same element on each of my pages
问题 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 ? 回答1: Laravel has a feature called view composer ,which lets you do some actions when a template file is