filamentphp/filament · error · LogicException
MorphToSelect type [{$this->getModel()}] must have a [titleA
Error message
MorphToSelect type [{$this->getModel()}] must have a [titleAttribute()] set. What it means
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.
Source
Thrown at packages/forms/src/Components/MorphToSelect/Type.php:353
}
public function getAlias(): string
{
return app($this->getModel())->getMorphClass();
}
/**
* @return array<string>
*/
public function getSearchColumns(): ?array
{
return $this->searchColumns ?? [$this->getTitleAttribute()];
}
public function getTitleAttribute(): string
{
if (blank($this->titleAttribute)) {
throw new LogicException("MorphToSelect type [{$this->getModel()}] must have a [titleAttribute()] set.");
}
return $this->titleAttribute;
}
public function getOptionsLimit(): int
{
return $this->optionsLimit;
}
public function forceSearchCaseInsensitive(?bool $condition = true): static
{
$this->isSearchForcedCaseInsensitive = $condition;
return $this;
}
public function isSearchForcedCaseInsensitive(): ?boolView on GitHub (pinned to 53483fa934)
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.
Example fix
// before
MorphToSelect::make('commentable')
->types([
Type::make(User::class),
]),
// after
MorphToSelect::make('commentable')
->types([
Type::make(User::class)->titleAttribute('name'),
]), Defensive patterns
Strategy: validation
Validate before calling
// Validate morph types before building the select
foreach ($types as $type) {
if (blank($type->getTitleAttribute())) {
throw new InvalidArgumentException(
'MorphToSelect type [' . $type->getModel() . '] needs a titleAttribute().'
);
}
} Type guard
function morphTypeHasTitleAttribute(\Filament\Forms\Components\MorphToSelect\Type $type): bool
{
try {
$type->getTitleAttribute();
return true;
} catch (LogicException) {
return false;
}
} Prevention
- 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.
When it happens
Trigger: `MorphToSelect::make('commentable')->types([Type::make(User::class)])` with no `->titleAttribute(...)` on the type, when the select builds its options.
Common situations: Adding new target models to a morph select and forgetting the title column, or assuming the model's `name` attribute is picked up automatically.
Related errors
- The [tableConfiguration()] method must be set when using a [
- MorphToSelect of class [$morphToSelectClass] must have a uni
- The relationship [{$relationshipName}] does not exist on the
- Block of class [$blockClass] must have a unique name, passed
- The relationship [{$name}] does not exist on the model [{$th
AI-assisted analysis of filamentphp/filament@53483fa934 (2026-08-17).
Data as JSON: /api/errors/2815bce2a2011e58.
Report an issue: GitHub.