FilamentF
Filament17mo ago
morty

SelectFilter unique/distinct relationship value

I have a table of tickets that belong to a location. Some locations are in the same city. How can I use a SelectFilter to get a unique list of cities from the locations table to filter the tickets? This is my code so far:

Tables\Filters\SelectFilter::make('location.city')
    ->label('City')
    ->placeholder('All')
    ->relationship('location', 'city')
    ->multiple()
    ->preload()
    ->searchable(),


But this gives me a list of duplicated cities. I tried something like the following but unsuccessfully:

->relationship(
    'location',
    'city',
    fn (Builder $query): Builder => $query->distinct())


Not sure how to achieve this?
Was this page helpful?