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);
                        });
                    }),
Was this page helpful?