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
- Define the relation method on the model: `public function tags(): BelongsToMany { return $this->belongsToMany(Tag::class); }`.
- Use the relationship method name (`relationship('tags')`), not the foreign key or pivot column.
- 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
- Use the Eloquent relation method name, never the foreign-key column, in ->relationship().
- Add a schema lint that verifies every relationship() field against the model in CI.
- Remember ->relationship() implies Eloquent persistence; for static option lists use ->options().
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
- The relationship [{$relationshipName}] does not exist on the
- The relationship [{$relationshipName}] does not exist on the
- No [{$userClass}] model found. Please bind an authenticatabl
- No [{$userClass}] model found. Please bind an authenticatabl
- Block of class [$blockClass] must have a unique name, passed
AI-assisted analysis of filamentphp/filament@53483fa934 (2026-08-17).
Data as JSON: /api/errors/557cb99b203c7247.
Report an issue: GitHub.