filamentphp/filament · error · LogicException

The relationship [{$name}] does not exist on the model [{$th

Error message

The relationship [{$name}] does not exist on the model [{$this->getModel()}].

What it means

When `->relationship($name)` is set on a CheckboxList, Filament resolves the relation by calling the method named `$name` on the field's model instance. Before calling it, `getRelationship()` verifies the name is not a plain column (`hasAttribute`) and is a recognized relation (`isRelation`); if either check fails it throws this LogicException, because `$record->{$name}()` would return a non-relation.

Source

Thrown at packages/forms/src/Components/CheckboxList.php:423

            return ($this->shouldTranslateLabel) ? __($label) : $label;
        }

        return parent::getLabel();
    }

    public function getRelationship(): ?BelongsToMany
    {
        $name = $this->getRelationshipName();

        if (blank($name)) {
            return null;
        }

        $record = $this->getModelInstance();

        if ($record->hasAttribute($name) || (! $record->isRelation($name))) {
            throw new LogicException("The relationship [{$name}] does not exist on the model [{$this->getModel()}].");
        }

        return $record->{$name}();
    }

    public function getRelationshipName(): ?string
    {
        return $this->evaluate($this->relationship);
    }

    public function isBulkToggleable(): bool
    {
        return (bool) $this->evaluate($this->isBulkToggleable);
    }

    public function getEnumDefaultStateCast(): ?StateCast
    {
        $enum = $this->getEnum();

View on GitHub (pinned to 53483fa934)

Solutions

  1. Define the relation method on the model: `public function tags(): BelongsToMany { return $this->belongsToMany(Tag::class); }`.
  2. Use the relationship method name (`relationship('tags')`), not the foreign key or pivot column.
  3. If the options come from a static source, drop `->relationship()` and use `->options()` with `->live()`/save handling instead.

Example fix

// before
CheckboxList::make('technologies')
    ->relationship('technology_ids'), // column, not a relation

// after
CheckboxList::make('technologies')
    ->relationship('technologies'), // matches `technologies()` on the model
Defensive patterns

Strategy: validation

Validate before calling

// Preflight before rendering a relationship-backed CheckboxList
$modelInstance = $modelClass::newInstance();
$relationshipName = 'technologies';

if ($modelInstance->hasAttribute($relationshipName)
    || (! $modelInstance->isRelation($relationshipName))) {
    throw new InvalidArgumentException(
        "[{$relationshipName}] is not a relationship on [{$modelClass}]."
    );
}

Type guard

function modelHasRelation(string|object $model, string $name): bool
{
    $instance = is_object($model) ? $model : new $model();

    return (! $instance->hasAttribute($name)) && $instance->isRelation($name);
}

Prevention

When it happens

Trigger: `CheckboxList::make('tags')->relationship()` on a model with no `tags()` relation; `->relationship('category_id')` pointing at a foreign-key column instead of the relation method; a misspelled relationship name.

Common situations: The `belongsToMany` was never defined on the Eloquent model, the developer used the table column name rather than the relation name, or the field is attached to a plain/DTO-backed model that has no relations at all.

Related errors


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