filamentphp/filament · error · LogicException
The relationship [{$relationshipName}] does not exist on the
Error message
The relationship [{$relationshipName}] does not exist on the model [{$this->getModel()}]. What it means
`ModalTableSelect::getRelationship()` supports dot-chained names by walking each segment: every hop must not be a plain attribute and must pass `isRelation()` on the current record's model. If any hop fails, `$relationship` stays null and a LogicException naming the full chain is thrown instead of returning a broken query.
Source
Thrown at packages/forms/src/Components/ModalTableSelect.php:762
foreach (explode('.', $relationshipName) as $nestedRelationshipName) {
if ($record->hasAttribute($nestedRelationshipName)) {
$relationship = null;
break;
}
if (! $record->isRelation($nestedRelationshipName)) {
$relationship = null;
break;
}
$relationship = $record->{$nestedRelationshipName}();
$record = $relationship->getRelated();
}
if (! $relationship) {
throw new LogicException("The relationship [{$relationshipName}] does not exist on the model [{$this->getModel()}].");
}
return $relationship;
}
public function getRelationshipName(): ?string
{
return $this->evaluate($this->relationship);
}
public function getSelectedRecord(): ?Model
{
if ($this->cachedSelectedRecord) {
return $this->cachedSelectedRecord;
}
if (blank($this->getState())) {
return null;View on GitHub (pinned to 53483fa934)
Solutions
- Define every missing hop on the model: `public function team(): BelongsTo { ... }` and `public function users(): HasMany { ... }`.
- Check each segment with `isRelation()` on the corresponding model to pinpoint the failing hop.
- Simplify to a single existing relationship or use `->options()` with a custom query if the chain does not exist.
Example fix
// before — `Project` has no `members()` relation
ModalTableSelect::make('user_id')
->relationship('members.id', 'name'),
// after
ModalTableSelect::make('user_id')
->relationship('team.users', 'name'), // both hops exist on the models Defensive patterns
Strategy: validation
Validate before calling
// Verify each hop of a dot-chained relationship before rendering
$record = $modelClass::newInstance();
foreach (explode('.', $relationshipName) as $segment) {
if ($record->hasAttribute($segment) || (! $record->isRelation($segment))) {
throw new InvalidArgumentException(
"Segment [{$segment}] of [{$relationshipName}] is not a relation on [" . $record::class . '].'
);
}
$record = $record->{$segment}()->getRelated();
} Type guard
function modelChainHasRelations(string $modelClass, string $dottedName): bool
{
$record = $modelClass::newInstance();
foreach (explode('.', $dottedName) as $segment) {
if ($record->hasAttribute($segment) || (! $record->isRelation($segment))) {
return false;
}
$record = $record->{$segment}()->getRelated();
}
return true;
} Prevention
- Add every hop of the chain to the model, and validate chains in a schema lint.
- Prefer short chains; intermediate models change and break long ones.
- Test the field renders against the real model in CI.
When it happens
Trigger: `->relationship('team.users')` where the model has no `team()` method (or any intermediate hop resolves to a non-relation); also a first-segment typo like `->relationship('usr')`.
Common situations: Selecting records from a related table through a chain, where an intermediate `hasMany`/`belongsTo` was renamed or never defined, or where a segment is actually a cast attribute.
Related errors
- The relationship [{$name}] does not exist on the model [{$th
- The relationship [{$relationshipName}] does not exist on the
- The [tableConfiguration()] method must be set when using a [
- No [{$userClass}] model found. Please bind an authenticatabl
- No [{$userClass}] model found. Please bind an authenticatabl
AI-assisted analysis of filamentphp/filament@53483fa934 (2026-08-17).
Data as JSON: /api/errors/be34b5e399b1c095.
Report an issue: GitHub.