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(): ?bool

View on GitHub (pinned to 53483fa934)

Solutions

  1. Set the display column: `Type::make(User::class)->titleAttribute('name')`.
  2. 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

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


AI-assisted analysis of filamentphp/filament@53483fa934 (2026-08-17). Data as JSON: /api/errors/2815bce2a2011e58. Report an issue: GitHub.