for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php namespace GeneaLabs\LaravelModelCaching\Console\Commands;
use Illuminate\Console\Command;
class Flush extends Command
{
protected $signature = 'modelCache:flush {--model=}';
protected $description = 'Flush cache for a given model.';
public function handle()
$option = $this->option('model');
if (! $option) {
$this->error("You must specify a model to flush a model's cache:");
$this->line("modelCache:flush --model=App\\Model");
return 1;
}
$model = new $option;
$usesCachableTrait = collect(class_uses($model))
->contains("GeneaLabs\LaravelModelCaching\Traits\Cachable");
if (! $usesCachableTrait) {
$this->error("'{$option}' is not an instance of CachedModel.");
$this->line("Only CachedModel instances can be flushed.");
$model->flushCache();
$this->info("✔︎ Cache for model '{$option}' has been flushed.");