Support the ongoing development of →
Database Eloquent Validation
Last updated 1 year ago.

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)

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 1 year ago.

Sign in to participate in this thread!


Your banner here too?


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

Your logo here?

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

© 2023 - All rights reserved.