8000 [12.x] Allows using `--model` and `--except` via `PruneCommand` command by hosni · Pull Request #56140 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

[12.x] Allows using --model and --except via PruneCommand command #56140

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

Merged
merged 1 commit into from
Jun 26, 2025

Conversation

hosni
Copy link
Contributor
@hosni hosni commented Jun 25, 2025

See: #56139

This will fix unreachable code when using both --model and --except at the same time on PruneCommand

@crynobone crynobone changed the title Fix: unreachable code on PruneCommand when using --model and --except [12.x] Allows using --model and --except via PruneCommand command Jun 26, 2025
Comment on lines +118 to +130
$models = $this->option('model');
$except = $this->option('except');

if (! empty($models) && ! empty($except)) {
if ($models && $except) {
throw new InvalidArgumentException('The --models and --except options cannot be combined.');
}

if ($models) {
return (new Collection($models))
->filter(static fn (string $model) => class_exists($model))
->values();
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, you use promptForMissingArgumentsUsing():

    protected function promptForMissingArgumentsUsing() {
        return [
            'model' => fn () => text(
                label: 'model',
                validate: ['model' => 'prohibited_with:except']
            ),
            'except' => fn () => text(
                label: 'model',
                validate: ['except' => 'prohibited_with:model']
            ),
        ];
    }

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can even go one step further:

    protected function afterPromptingForMissingArgumentsInputInterface $input, OutputInterface $output): void
    {
        $input->setOption('model', text(
            label: 'model',
            default: $this->option('model'),
            transform: fn ($models) => (new Collection($models))
                ->filter(static fn (string $model) => class_exists($model))
                ->values()
        ));
    }

@taylorotwell taylorotwell merged commit c0955af into laravel:12.x Jun 26, 2025
62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0