Skip to content

Instantly share code, notes, and snippets.

@wdmtech
Created October 23, 2015 10:15
Show Gist options
  • Save wdmtech/2ec736043b80409781fe to your computer and use it in GitHub Desktop.
Save wdmtech/2ec736043b80409781fe to your computer and use it in GitHub Desktop.
Quick 'n dirty Laravel 5 view (blade) cache, session file cache and debugbar cache delete command
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
class ClearCaches extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'clear:caches';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear view (blade) caches, debugbar caches and sessions.';
/**
* The file system instance.
*
* @var \Illuminate\Filesystem\Filesystem
*/
protected $files;
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
$this->files = new Filesystem;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
// View cache files
foreach ($this->files->files(storage_path('framework/views')) as $file)
{
$this->files->delete($file);
}
$this->info('View cache files deleted');
// Session cache files
foreach ($this->files->files(storage_path('framework/sessions')) as $file)
{
$this->files->delete($file);
}
$this->info('Session cache files deleted');
// Debugbar cache files
foreach ($this->files->files(storage_path('debugbar')) as $file)
{
$this->files->delete($file);
}
$this->info('DebugBar cache files deleted');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment