每次重新加载时删除Laravel的存储/视图文件 [英] Delete Laravel's storage/views files on each reload

查看:78
本文介绍了每次重新加载时删除Laravel的存储/视图文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的刀片很棒,但是缩小的尺寸是必须重新编译并创建html文件.

I am using blade which is great, however the downsize is that is has to be recompiled and html files are created.

因此,我需要找出在开发阶段如何在每次重新加载页面时删除存储视图内的所有文件.

So, I need to find out how to delete all filews inside storage views on each page reload, during the development stage.

任何想法是什么,easies php代码是什么,我应该放在哪里?在基本控制器中?在文件管理器或routes.php中?

Any idea what is the easies php code and where should I put it? In the base controller? in filers or routes.php?

感谢任何想法.我被困住了,需要一些建议在哪里放置删除代码,因此在刀片式服务器在存储/视图中被编译为html文件后,它不会被删除.

Thanks for any idea. I am stuck and need some advice where to put the delete code, so it is not deleted after the blade is compiled as html file in storage/views.

推荐答案

如果您运行的是PHP5或更高版本,则可以尝试以下方法.您可以根据环境或调试模式打开或关闭它.

If you are running PHP5 or higher, you can try the below. You can switch it on or off depending on enviornment or if debug mode is on.

<?php
if (env('APP_DEBUG') || env('APP_ENV') === 'local') 
    ini_set('opcache.revalidate_freq', '0');

您还可以只调用artisan命令以使用中间件或路由过滤器清除缓存.

You can also just call the artisan command to clear the cache using middleware or route filters.

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);
    }
}

这篇关于每次重新加载时删除Laravel的存储/视图文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆