Get location of view passed into laravel view composer

人盡茶涼 提交于 2019-12-24 15:08:48

问题


Is it possible to get the location of a view that is passed into a Laravel view composer?

View::composer('*', function($view) {
   // I want to find out the location of the view file here
   // e.g. master.something.header
   // then add this to an array
   $loadedViews = View::share("loadedViews");
   $loadedViews[] = $thisViewName;
});

The reason is that I want to have a variable that will be shared between views and contain an array of all the views that are loaded. Any css and js files will be located in directory structure that matches the views one.

This means I can then have a css and js view which then include the required css and js files for the views on the page. All css and js will be directly linked to a specific view.

If there is already a way to do this, or a way to get a list of loaded views, please let me know!


回答1:


$view->getName() was the answer that I wanted.

$view->getPath() is the actual path to the file.



来源:https://stackoverflow.com/questions/18943452/get-location-of-view-passed-into-laravel-view-composer

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