| Conditions | 3 |
| Paths | 3 |
| Total Lines | 24 |
| Code Lines | 14 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php namespace GeneaLabs\LaravelModelCaching\Console\Commands; |
||
| 10 | public function handle() |
||
| 11 | { |
||
| 12 | $option = $this->option('model'); |
||
| 13 | |||
| 14 | if (! $option) { |
||
| 15 | $this->error("You must specify a model to flush a model's cache:"); |
||
| 16 | $this->line("modelCache:flush --model=App\\Model"); |
||
| 17 | |||
| 18 | return 1; |
||
| 19 | } |
||
| 20 | |||
| 21 | $model = new $option; |
||
| 22 | $usesCachableTrait = collect(class_uses($model)) |
||
| 23 | ->contains("GeneaLabs\LaravelModelCaching\Traits\Cachable"); |
||
| 24 | |||
| 25 | if (! $usesCachableTrait) { |
||
| 26 | $this->error("'{$option}' is not an instance of CachedModel."); |
||
| 27 | $this->line("Only CachedModel instances can be flushed."); |
||
| 28 | |||
| 29 | return 1; |
||
| 30 | } |
||
| 31 | |||
| 32 | $model->flushCache(); |
||
| 33 | $this->info("✔︎ Cache for model '{$option}' has been flushed."); |
||
| 34 | } |
||
| 36 |