F
Filamentβ€’16mo ago
Sesh

How to use deep relations in filters in the V3 Table Builder?

Is there a way to use deep relations in filters in V3? I have the following relation: News => belongsToMany => players => belongsTo => playerCategory Which is defined in the News Model like this (and works):
public function playerCategories()
{
return $this->hasManyDeepFromRelations($this->players(), (new Player())->playerCategory());
}
public function playerCategories()
{
return $this->hasManyDeepFromRelations($this->players(), (new Player())->playerCategory());
}
I want to add a Filter for playerCategories in the News table builder component. I tried this:
SelectFilter::make('playerCategories')
->label(__('Player Categories'))
->preload()
->relationship(playerCategories', 'name_en')
->multiple(),
SelectFilter::make('playerCategories')
->label(__('Player Categories'))
->preload()
->relationship(playerCategories', 'name_en')
->multiple(),
And got this error:
Filament\Forms\Components\Select::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\BelongsToMany|Znck\Eloquent\Relations\BelongsToThrough|null, Staudenmeir\EloquentHasManyDeep\HasManyDeep returned
Filament\Forms\Components\Select::getRelationship(): Return value must be of type Illuminate\Database\Eloquent\Relations\BelongsTo|Illuminate\Database\Eloquent\Relations\BelongsToMany|Znck\Eloquent\Relations\BelongsToThrough|null, Staudenmeir\EloquentHasManyDeep\HasManyDeep returned
Does anyone know how to achieve this? Thanks πŸ™
Solution:
I don't think ->relationship() supports HasManyDeep You have to provide ->options() & ->query() manually...
Jump to solution
2 Replies
Solution
ZedoX
ZedoXβ€’16mo ago
I don't think ->relationship() supports HasManyDeep You have to provide ->options() & ->query() manually
Sesh
SeshOPβ€’16mo ago
Thats seems to be the way, thanks.
Want results from more Discord servers?
Add your server