我使用的是blade,这很好,但缺点是必须重新编译并创建html文件。
因此,在开发阶段,我需要了解如何在每次重新加载页面时删除存储视图中的所有文件。
知道什么是easies php代码吗?我应该把它放在哪里?在基本控制器中?在filers或routes.php中?
谢谢你的任何想法。我被卡住了,需要一些建议将删除代码放在哪里,所以在刀片被编译为存储/视图中的html文件后,它不会被删除。
如果您正在运行PHP5或更高版本,您可以尝试以下操作。您可以根据环境或调试模式是否打开来打开或关闭它。
<?php
if (env('APP_DEBUG') || env('APP_ENV') === 'local')
ini_set('opcache.revalidate_freq', '0');
您也可以调用artisan命令,使用中间件或路由过滤器清除缓存。
Laravel 4
<?php
App::before(function($request)
{
if (env('APP_DEBUG') || env('APP_ENV') === 'local')
Artisan::call('view:clear');
});
Laravel 5+中间件:
<?php
namespace App'Http'Middleware;
use Artisan;
use Closure;
class ClearViewCache
{
/**
* Handle an incoming request.
*
* @param 'Illuminate'Http'Request $request
* @param 'Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (env('APP_DEBUG') || env('APP_ENV') === 'local')
Artisan::call('view:clear');
return $next($request);
}
}