{"record":{"id":"2815bce2a2011e58","repo":"filamentphp/filament","slug":"morphtoselect-type-this-getmodel-must-have","errorCode":null,"errorMessage":"MorphToSelect type [{$this->getModel()}] must have a [titleAttribute()] set.","messagePattern":"MorphToSelect type \\[(.+?)\\] must have a \\[titleAttribute\\(\\)\\] set\\.","errorType":"exception","errorClass":"LogicException","httpStatus":null,"severity":"error","filePath":"packages/forms/src/Components/MorphToSelect/Type.php","lineNumber":353,"sourceCode":"    }\n\n    public function getAlias(): string\n    {\n        return app($this->getModel())->getMorphClass();\n    }\n\n    /**\n     * @return array<string>\n     */\n    public function getSearchColumns(): ?array\n    {\n        return $this->searchColumns ?? [$this->getTitleAttribute()];\n    }\n\n    public function getTitleAttribute(): string\n    {\n        if (blank($this->titleAttribute)) {\n            throw new LogicException(\"MorphToSelect type [{$this->getModel()}] must have a [titleAttribute()] set.\");\n        }\n\n        return $this->titleAttribute;\n    }\n\n    public function getOptionsLimit(): int\n    {\n        return $this->optionsLimit;\n    }\n\n    public function forceSearchCaseInsensitive(?bool $condition = true): static\n    {\n        $this->isSearchForcedCaseInsensitive = $condition;\n\n        return $this;\n    }\n\n    public function isSearchForcedCaseInsensitive(): ?bool","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/filamentphp/filament/blob/53483fa9340e4ec637985fe454ebb58afb92ea24/packages/forms/src/Components/MorphToSelect/Type.php#L335-L371","documentation":"Each `MorphToSelect\\Type` renders options and search columns from a title attribute; `getSearchColumns()` defaults to `[getTitleAttribute()]`, and `getTitleAttribute()` throws this LogicException when `titleAttribute()` was never set on the type — there is no column to build option labels from.","triggerScenarios":"`MorphToSelect::make('commentable')->types([Type::make(User::class)])` with no `->titleAttribute(...)` on the type, when the select builds its options.","commonSituations":"Adding new target models to a morph select and forgetting the title column, or assuming the model's `name` attribute is picked up automatically.","solutions":["Set the display column: `Type::make(User::class)->titleAttribute('name')`.","Optionally add `->searchColumns(['first_name', 'last_name'])` to control searching — but keep `titleAttribute()` set for labels."],"exampleFix":"// before\nMorphToSelect::make('commentable')\n    ->types([\n        Type::make(User::class),\n    ]),\n\n// after\nMorphToSelect::make('commentable')\n    ->types([\n        Type::make(User::class)->titleAttribute('name'),\n    ]),","handlingStrategy":"validation","validationCode":"// Validate morph types before building the select\nforeach ($types as $type) {\n    if (blank($type->getTitleAttribute())) {\n        throw new InvalidArgumentException(\n            'MorphToSelect type [' . $type->getModel() . '] needs a titleAttribute().'\n        );\n    }\n}","typeGuard":"function morphTypeHasTitleAttribute(\\Filament\\Forms\\Components\\MorphToSelect\\Type $type): bool\n{\n    try {\n        $type->getTitleAttribute();\n\n        return true;\n    } catch (LogicException) {\n        return false;\n    }\n}","tryCatchPattern":null,"preventionTips":["Make ->titleAttribute() part of your Type::make() template in every morph config.","Set ->searchColumns() explicitly when the title column is not the search column.","Add a CI schema lint that walks morph types and checks for a title attribute."],"tags":["filament","forms","morph-to-select","missing-configuration"],"backgroundTag":"missing-required-configuration","analyzedSha":"53483fa9340e4ec637985fe454ebb58afb92ea24","analyzedAt":"2026-08-17T02:06:23.049Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}