简体   繁体   English

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

[英]Laravel 5 - Load views blade file from storage folder

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

Yes, you have a couple of choices. 是的,你有几个选择。


1. Add another path to your view config file 1.添加另一个路径到您的视图配置文件

Open up config/view.php and add your new path to the paths array: 打开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.php and 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');

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')),
];
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM