Support the ongoing development of Laravel.io →
Database Eloquent Validation
Last updated 2 years ago.
0

Hello!
I recently worked on a project with a similar task. My query for checking overlappings was big so I thought how to reduce it. After some time of analysis it became very simple, and lgical.

User::whereNotHas('availabilities', function($q)use($selected_date_time)
                                   {
                                    $q->where('unavailable_start_date', '<', $selected_date_time)
                                    ->where('unavailable_end_date', '>', $selected_date_time)
                                    ;
                                   })
                            ->with('availabilities')
                                                        ->get();

I'm not sure if there is a whereNotHas method, but it would work. Your query would return all users except those who have all availabilities unavailable.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.