© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
6 replies
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(),
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())
->relationship(
    'location',
    'city',
    fn (Builder $query): Builder => $query->distinct())


Not sure how to achieve this?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Struggling with SelectFilter with relationship() and distinct status (Enum)
FilamentFFilament / ❓┊help
16mo ago
SelectFilter relationship field
FilamentFFilament / ❓┊help
3y ago
TextColumn relationship unique values
FilamentFFilament / ❓┊help
3y ago
Distinct Values in a relationship filter
FilamentFFilament / ❓┊help
2y ago