© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
5 replies
Sydd

filter record in relations model

Hello everyone, I want some advice, direction... I have a Truck Driver model that is related to the db table drives... on the index page where all the truck drivers are, I show the number of kilometers per year, month, etc. how to correctly set such a filter ... so that I only have distinct values ​​from the db tables drives ... and then the query is also correctly adjusted in the driver according to the selected year. As stated below ... the filter returns the $id of records in drives with years, so I have 256x 2023 ... etc. If someone would direct me in which direction to go for the solution. Well thank you.
 SelectFilter::make('year')
        ->label('Year')
        ->native(false)
        ->relationship('drives', 'year')
        ->options(Drive::query()->select('year')->distinct()->get()->pluck('year', 'year')->toArray()) 
 SelectFilter::make('year')
        ->label('Year')
        ->native(false)
        ->relationship('drives', 'year')
        ->options(Drive::query()->select('year')->distinct()->get()->pluck('year', 'year')->toArray()) 

Seems to ->options dont aply to filer ....
Solution
Thanks, for answer, its works according your advice. But finaly in the main table is calculated values, and dont work with sorting, search etc. I take care about create a db table as overview and next use. Rly thanks for yours engagement.
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Unnecessary SQL in select filter using relations
FilamentFFilament / ❓┊help
2y ago
Pass record to Relations Manager Modal
FilamentFFilament / ❓┊help
3y ago
Repeater: TextInput action always returning last record in Model $record
FilamentFFilament / ❓┊help
4mo ago
Access model $record issue in Select (pluck)
FilamentFFilament / ❓┊help
3y ago