Reputation: 2577
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.
Any idea what is the easies php code and where should I put it? In the base controller? in filers or routes.php?
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.
Upvotes: 2
Views: 2369
Reputation: 180
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');
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+ Middleware:
<?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);
}
}
Upvotes: 7