Laravel 5 - 从存储文件夹加载视图刀片文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32373644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:17:40  来源:igfitidea点击:

Laravel 5 - Load views blade file from storage folder

phplaravellaravel-5.1

提问by Hussaini Zulkifli

Is it possible to load views from storagefolder instead from resources\views?

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

回答by user2479930

Yes, you have a couple of choices.

是的,你有几个选择。



1. Add another path to your view config file

1. 添加另一个路径到您的视图配置文件

Open up config/view.phpand add your new path to the pathsarray:

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

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

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

Laravel 将返回第一个匹配的视图,所以一定要相应地对路径进行排序。



2. Add a view namespace

2. 添加视图命名空间

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

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

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

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

有了这个,您可以使用前缀访问视图,例如custom_name

return view('custom_name::home');

回答by RaMeSh

Yes it is possible.

对的,这是可能的。

Just config your view.php file like this

只需像这样配置您的 view.php 文件

<?php

return
     ['paths' => [realpath(base_path('storage/views')),],

      'compiled' => realpath(storage_path('framework/views')),
];
?>