Skip to content

Instantly share code, notes, and snippets.

@cjonstrup
Last active August 1, 2019 21:17
Show Gist options
  • Save cjonstrup/8228165 to your computer and use it in GitHub Desktop.
Save cjonstrup/8228165 to your computer and use it in GitHub Desktop.
Clear Laravel 4.* app/storage/views artisan views:clear
<?php
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
class ViewsCommand extends Command {
/**
* The console command name.
*
* @var string
*/
protected $name = 'views:clear';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Clear views folder';
/**
* 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 \Illuminate\Filesystem\Filesystem;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
foreach ($this->files->files(storage_path().'/views') as $file)
{
$this->files->delete($file);
}
$this->info('Views deleted from cache');
}
}
@ladame
Copy link

ladame commented Sep 25, 2014

Thanks cjonstrup !

For newbie, don't forget to register that command before use it :
http://laravel.com/docs/4.2/commands#registering-commands

@taly2808
Copy link

taly2808 commented Oct 7, 2014

Thanks so much!
It's really useful and save my time.

@adanarchila
Copy link

Thanks sir, you rock!

@PieterScheffers
Copy link

Don't you miss continuing on .gitignore file? Or doesn't it get listed because it's a hidden dot file?

@halilim
Copy link

halilim commented Mar 7, 2015

Shouldn't this be a PR to Laravel?

@boy1583
Copy link

boy1583 commented May 31, 2016

That's really helpful for me ! Thx !

@2bj
Copy link

2bj commented Aug 1, 2019

<?php

use Illuminate\Console\Command;

class ViewsCommand extends Command
{

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'views:clear';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Clear views folder';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function fire()
    {
        File::cleanDirectory(storage_path('views'));

        $this->info('Views deleted from cache');
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment