© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
13 replies
varovas

Eager loaded relationships filter

Hi, does anyone know how make a filter that would filter record's relationships. What I basically need is I want to display all users, but be able to filter how many posts have they posted between 2 dates. Below you can see the code I tries, but somehow it does not work. Or maybe it is not possible that way?
Filter::make('start')
                    ->form([
                        DatePicker::make('start_date')->label('Start Date'),
                    ])
                    ->query(function ($query, array $data) {
                        $startDate = Carbon::parse($data['start_date'])->format('Y-m-d');
                        return $query->with('posts', function ($q) use ($startDate) {
                           $q->where('date', '>=', $startDate);
                        });
                    }),
Filter::make('start')
                    ->form([
                        DatePicker::make('start_date')->label('Start Date'),
                    ])
                    ->query(function ($query, array $data) {
                        $startDate = Carbon::parse($data['start_date'])->format('Y-m-d');
                        return $query->with('posts', function ($q) use ($startDate) {
                           $q->where('date', '>=', $startDate);
                        });
                    }),
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

Problem: Exporter Not Working with Eager-Loaded Relationships
FilamentFFilament / ❓┊help
13mo ago
Eager loaded relationship based on table filter
FilamentFFilament / ❓┊help
3y ago
Using eager loaded relationships in custom table column views
FilamentFFilament / ❓┊help
2y ago
Eager loading relationships in table
FilamentFFilament / ❓┊help
2y ago