FilamentF
Filamentβ€’3y 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());
}


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(),


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


Does anyone know how to achieve this? Thanks πŸ™
Solution
I don't think ->relationship() supports HasManyDeep

You have to provide ->options() & ->query() manually
Was this page helpful?