laravel 清除 Lumen 上的视图缓存
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32301366/
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
Clear views cache on Lumen
提问by henriale
Few weeks ago, I had the same problem in Laravel 5.1, which I could solve with this solution.
几周前,我在 Laravel 5.1 中遇到了同样的问题,我可以用这个解决方案解决。
However, now I'm facing the same issue in Lumen, but I can't call php artisan view:clear
to clear the cached files. There is any other way?
但是,现在我在 Lumen 中遇到了同样的问题,但是我无法调用php artisan view:clear
来清除缓存的文件。还有其他方法吗?
Thanks!
谢谢!
回答by baao
There's no command for the view cache in lumen, but you can easily create your own or use my mini package found at the end of the answer.
流明中没有视图缓存命令,但您可以轻松创建自己的或使用我在答案末尾找到的迷你包。
First, put this file inside your app/Console/Commands
folder (make sure to change the namespace if your app has a different than App):
首先,将此文件放在您的app/Console/Commands
文件夹中(如果您的应用程序与 App 不同,请确保更改命名空间):
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ClearViewCache extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $name = 'view:clear';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear all compiled view files.';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$cachedViews = storage_path('/framework/views/');
$files = glob($cachedViews.'*');
foreach($files as $file) {
if(is_file($file)) {
@unlink($file);
}
}
}
}
Then open app/Console/Kernel.php
and put the command inside the $commands
array (again, mind the namespace):
然后打开app/Console/Kernel.php
并将命令放入$commands
数组中(再次注意命名空间):
protected $commands = [
'App\Console\Commands\ClearViewCache'
];
You can verify that everything worked by running
您可以通过运行来验证一切是否正常
php artisan
inside the project's root.
在项目的根目录中。
You will now see the newly created command:
您现在将看到新创建的命令:
You can now run it like you did in laravel.
您现在可以像在 laravel 中一样运行它。
EDIT
编辑
I've created a small (MIT) packagefor this, you can require it with composer:
我为此创建了一个小 (MIT)包,您可以使用 composer 要求它:
composer require baao/clear-view-cache
then add
然后加
$app->register('Baao\ClearViewCache\ClearViewCacheServiceProvider');
to bootsrap/app.php
and run it with
以bootsrap/app.php
与运行
php artisan view:clear