{"record":{"id":"3df4a7b3bc63d0bd","repo":"laravel/framework","slug":"the-model-and-except-options-cannot-be-combine","errorCode":null,"errorMessage":"The --model and --except options cannot be combined.","messagePattern":"The --model and --except options cannot be combined\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Console/PruneCommand.php","lineNumber":124,"sourceCode":"        if ($total == 0) {\n            $this->components->info(\"No prunable [$model] records found.\");\n        }\n    }\n\n    /**\n     * Determine the models that should be pruned.\n     *\n     * @return \\Illuminate\\Support\\Collection\n     *\n     * @throws \\InvalidArgumentException\n     */\n    protected function models()\n    {\n        $models = $this->option('model');\n        $except = $this->option('except');\n\n        if ($models && $except) {\n            throw new InvalidArgumentException('The --model and --except options cannot be combined.');\n        }\n\n        if ($models) {\n            return (new Collection($models))\n                ->filter(static fn (string $model) => class_exists($model))\n                ->values();\n        }\n\n        return (new Collection(Finder::create()->in($this->getPath())->files()->name('*.php')))\n            ->map(function ($model) {\n                $namespace = $this->laravel->getNamespace();\n\n                return $namespace.str_replace(\n                    ['/', '.php'],\n                    ['\\\\', ''],\n                    Str::after($model->getRealPath(), realpath(app_path()).DIRECTORY_SEPARATOR)\n                );\n            })","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Console/PruneCommand.php#L106-L142","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasting flags from documentation; attempting to both target and exclude in one command; scripting prune jobs with conflicting flags.","solutions":["Drop one of the flags: use --model for an explicit allow-list, or --except to remove models from auto-discovery.","If you need a complex set, use only --model and list exactly the models you want pruned.","Run separate prune commands if you genuinely need both behaviors at different times."],"exampleFix":"# before\nphp artisan model:prune --model='App\\Models\\User' --except='App\\Models\\Archive'\n\n# after\nphp artisan model:prune --except='App\\Models\\Archive'","handlingStrategy":"validation","validationCode":"if ($this->option('model') && $this->option('except')) {\n    throw new \\InvalidArgumentException(\n        'Use either --model or --except, not both.'\n    );\n}","typeGuard":"function pruneOptionsAreExclusive(array $options): bool {\n    return empty($options['model']) || empty($options['except']);\n}","tryCatchPattern":null,"preventionTips":["Pass only one of --model / --except to model:prune.","In automation scripts, validate flags before invoking the command.","Document the mutual exclusion for ops teams running prune jobs."],"tags":["database","eloquent","console","artisan","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}