Skip to content

Commit

Permalink
Add optional 'exclude' parameter to exclude auto-detected models from…
Browse files Browse the repository at this point in the history
… being pruned
  • Loading branch information
jochensengier committed Nov 24, 2021
1 parent dcda06f commit 779adea
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Illuminate/Database/Console/PruneCommand.php
Expand Up @@ -19,6 +19,7 @@ class PruneCommand extends Command
*/
protected $signature = 'model:prune
{--model=* : Class names of the models to be pruned}
{--exclude=* : Class names of the models to be excluded}
{--chunk=1000 : The number of models to retrieve per chunk of models to be deleted}
{--pretend : Display the number of prunable records found instead of deleting them}';

Expand Down Expand Up @@ -87,6 +88,8 @@ protected function models()
return collect($models);
}

$exclude = $this->option('exclude');

return collect((new Finder)->in(app_path('Models'))->files()->name('*.php'))
->map(function ($model) {
$namespace = $this->laravel->getNamespace();
Expand All @@ -96,6 +99,10 @@ protected function models()
['\\', ''],
Str::after($model->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
);
})->when(! empty($exclude), function ($models) use ($exclude) {
return $models->filter(function ($model) use ($exclude) {
return ! in_array($model, $exclude);
});
})->filter(function ($model) {
return $this->isPrunable($model);
})->values();
Expand Down

0 comments on commit 779adea

Please sign in to comment.