我想在我的标题中包含我的Settings
模型中的数据,该标题包含在所有页面中。
如何在所有页面加载中包含此内容?通常我通过我的控制器内的Settings
集合发送,但有没有办法在全球范围内执行此操作?
如果您的标题是它自己的包含,则可以使用View Composer在呈现时自动将数据传递到该特定视图:
View::composer('your.header.include', function ($view) {
$view->with('settings', Setting::all());
});
把它扔在服务提供商boot
方法中。 your.header.include
是您需要settings
的视图文件的名称。
在AppServiceProvider中使用View :: share
https://laravel.com/docs/5.5/views#sharing-data-with-all-views