Laravel 5-从存储文件夹加载视图刀片文件 [英] Laravel 5 - Load views blade file from storage folder

查看:69
本文介绍了Laravel 5-从存储文件夹加载视图刀片文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以从storage文件夹而不是从resources\views加载视图?

Is it possible to load views from storage folder instead from resources\views?

推荐答案

是的,您有两种选择.

打开config/view.php并将新路径添加到paths数组:

Open up config/view.php and add your new path to the paths array:

'paths' => [
    storage_path(),
    realpath(base_path('resources/views')),
],

Laravel将返回最先匹配的任何视图,因此请确保对路径进行相应的排序.

Laravel will return whichever view that matches first, so be sure to sort the paths accordingly.

打开app/Providers/AppServiceProvider.php并添加新的视图命名空间:

Open up app/Providers/AppServiceProvider.php and add your new view namespace:

public function boot()
{
    $this->loadViewsFrom(storage_path(), 'custom_name');
}

这样,您可以使用诸如custom_name的前缀访问视图:

With this you can access the views with a prefix like custom_name:

return view('custom_name::home');

这篇关于Laravel 5-从存储文件夹加载视图刀片文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆