Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Add an option to specify the default path to the models directory for php artisan model:prune #49617

Merged
merged 4 commits into from Jan 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/Illuminate/Database/Console/PruneCommand.php
Expand Up @@ -23,7 +23,8 @@ class PruneCommand extends Command
{--model=* : Class names of the models to be pruned}
{--except=* : Class names of the models to be excluded from pruning}
{--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}';
{--pretend : Display the number of prunable records found instead of deleting them}
{--path=* : Absolute path(s) to directories where models are located}';

/**
* The console command description.
Expand Down Expand Up @@ -96,7 +97,7 @@ protected function models()
throw new InvalidArgumentException('The --models and --except options cannot be combined.');
}

return collect((new Finder)->in($this->getDefaultPath())->files()->name('*.php'))
return collect((new Finder)->in($this->getPath())->files()->name('*.php'))
->map(function ($model) {
$namespace = $this->laravel->getNamespace();

Expand All @@ -115,12 +116,16 @@ protected function models()
}

/**
* Get the default path where models are located.
* Get the path where models are located.
*
* @return string
*/
protected function getDefaultPath()
protected function getPath()
{
if (! empty($path = $this->option('path'))) {
return $path;
}

return app_path('Models');
}

Expand Down