laravel/framework · error · InvalidArgumentException

The --model and --except options cannot be combined.

Error message

The --model and --except options cannot be combined.

What it means

Thrown by PruneCommand::models() (the `model:prune` command) when both --model and --except options are supplied. The two options are mutually exclusive: --model restricts pruning to an explicit list, while --except excludes specific models from auto-discovery. Supplying both is ambiguous, so the command rejects it.

Solutions

  1. Drop one of the flags: use --model for an explicit allow-list, or --except to remove models from auto-discovery.
  2. If you need a complex set, use only --model and list exactly the models you want pruned.
  3. Run separate prune commands if you genuinely need both behaviors at different times.

Example fix

# before
php artisan model:prune --model='App\Models\User' --except='App\Models\Archive'

# after
php artisan model:prune --except='App\Models\Archive'
Defensive patterns

Strategy: validation

Validate before calling

if ($this->option('model') && $this->option('except')) {
    throw new \InvalidArgumentException(
        'Use either --model or --except, not both.'
    );
}

Type guard

function pruneOptionsAreExclusive(array $options): bool {
    return empty($options['model']) || empty($options['except']);
}

Prevention

When it happens

Trigger: Running `php artisan model:prune --model=App\Models\User --except=App\Models\Archive` (note: shell escaping of backslashes required). Any invocation where both option arrays are non-empty.

Common situations: Copy-pasting flags from documentation; attempting to both target and exclude in one command; scripting prune jobs with conflicting flags.

Related errors


AI-assisted analysis of laravel/framework@e0f6eb3518 (2026-08-11). Data as JSON: /api/errors/3df4a7b3bc63d0bd. Report an issue: GitHub.

Appendix: source

Thrown at src/Illuminate/Database/Console/PruneCommand.php:124

        if ($total == 0) {
            $this->components->info("No prunable [$model] records found.");
        }
    }

    /**
     * Determine the models that should be pruned.
     *
     * @return \Illuminate\Support\Collection
     *
     * @throws \InvalidArgumentException
     */
    protected function models()
    {
        $models = $this->option('model');
        $except = $this->option('except');

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

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

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

                return $namespace.str_replace(
                    ['/', '.php'],
                    ['\\', ''],
                    Str::after($model->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)
                );
            })

View on GitHub (pinned to e0f6eb3518)