Laravel : having the same element on each of my pages

喜你入骨 提交于 2019-12-24 02:06:47

问题


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 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.



来源:https://stackoverflow.com/questions/35105578/laravel-having-the-same-element-on-each-of-my-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!