© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
1 reply
Sjoerd24

Making a (readonly) Repeater with a custom query

So I am making a system for making schedules(=Schedules) for employees and manage their vacations (=Absences). Users are added to the schedules with a pivot table (schedule_user). Now I am trying to make something like the pictures and I am almost there!

What I want is that if you select the user/start_Date/end_date that it automaticly looks up all the conflicting schedules and counts the hours. The overview I want to display in a simple TableRepeater. This is the code I now have:

TableRepeater::make('scheduleUsers')
    ->visible(fn (Get $get) => $get('start_date') && $get('end_date') && $get('subject_id'))
    ->addable(false)
    ->deletable(false)
    ->relationship('scheduleUsers',
       modifyQueryUsing: function (Builder $query, Get $get) {
         if($get('start_date') && $get('end_date') && $get('subject_id')) {
            $query
                ->where('schedule_user.user_id', $get('subject_id'))
                ->whereHas('schedule', function (Builder $query) use ($get) {
                   $query->where('start_date', '>=', $get('start_date'));
                   $query->where('end_date', '<=', $get('end_date'));
                        });
                    }
                })
TableRepeater::make('scheduleUsers')
    ->visible(fn (Get $get) => $get('start_date') && $get('end_date') && $get('subject_id'))
    ->addable(false)
    ->deletable(false)
    ->relationship('scheduleUsers',
       modifyQueryUsing: function (Builder $query, Get $get) {
         if($get('start_date') && $get('end_date') && $get('subject_id')) {
            $query
                ->where('schedule_user.user_id', $get('subject_id'))
                ->whereHas('schedule', function (Builder $query) use ($get) {
                   $query->where('start_date', '>=', $get('start_date'));
                   $query->where('end_date', '<=', $get('end_date'));
                        });
                    }
                })

This results in the following query that I intercepted with debugbar:
select * from `schedule_user` where `schedule_user`.`user_id` is null and `schedule_user`.`user_id` is not null and `schedule_user`.`user_id` = '1' and exists (select * from `schedules` where `schedule_user`.`schedule_id` = `schedules`.`id` and `start_date` >= '2024-05-06' and `end_date` <= '2024-05-18')
select * from `schedule_user` where `schedule_user`.`user_id` is null and `schedule_user`.`user_id` is not null and `schedule_user`.`user_id` = '1' and exists (select * from `schedules` where `schedule_user`.`schedule_id` = `schedules`.`id` and `start_date` >= '2024-05-06' and `end_date` <= '2024-05-18')

This query returns null because of this part: "
schedule_user
schedule_user
.
user_id
user_id
is null and
schedule_user
schedule_user
.
user_id
user_id
is not null and". If you would delete that part the query would work perfectly. My question is, why is this added to the query?
image.png
image.png
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

Custom query for repeater
FilamentFFilament / ❓┊help
3y ago
Custom Repeater button
FilamentFFilament / ❓┊help
2y ago
Custom repeater validation
FilamentFFilament / ❓┊help
3y ago
Problem with repeater at custom page
FilamentFFilament / ❓┊help
2y ago