如何禁用Laravel视图缓存?
我的一个观点有一个例外.但是,laravel并没有告诉我视图的名称以便可以找到并修复它,而是在app/storage/views/110a3ecc0aa5ab7e6f7f50ef35a67a8b
中使用,这是没有意义的.
I have an exception in one of my views. However, instead of telling me the name of the view so I can find it and fix it, laravel says it is in app/storage/views/110a3ecc0aa5ab7e6f7f50ef35a67a8b
, which is meaningless.
如何禁用此视图缓存,以便laravel使用并引用实际文件?
How do I disable this view caching, so that laravel uses and refers to the actual files?
开箱即用?你不能但是您可以扩展BladeCompiler类,覆盖可用于检查视图是否已过期的方法:
Out of the box? You can't. But you can extend the BladeCompiler class, overriding the method resposible for checking if the view has been expired:
class MyBladeCompiler extends BladeCompiler {
public function isExpired($path)
{
if ( ! \Config::get('view.cache'))
{
return true;
}
return parent::isExpired($path);
}
}
您需要使用自己的编译器替换IoC容器中的BladeCompiler实例:
You'll need to replace the BladeCompiler instance in IoC container, with your own compiler:
$app = App::make('app'); // or just $app = app();
$app->bindShared('blade.compiler', function($app)
{
$cache = $app['path.storage'].'/views';
return new MyBladeCompiler($app['files'], $cache);
});
然后您只需要在app/config/view.php文件中创建该密钥
And then you just need to create that key in your app/config/view.php file
<?php
return [
'cache' => false,
'paths' => [base_path().'/resources/views'],
'pagination' => 'pagination::slider-3',
];
或者,就像我在这里所做的:
Or, like I do here:
return [
'cache' => in_array(App::environment(), ['production', 'staging']),
];