Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MudassirAbbas's avatar

kindly help me to make search query . i want tos search cars those have not reservation between date and time slots

$pickupDate = 2017-10-23 $returnDate = 2017-10-23 $pickupTime = "9:00:00" $returnTime = "11:00:00" $cars = Car::where("availability",true)->whereDoesntHave('User', function ($cars) use ($pickupDate,$pickupTime,$returnDate,$returnTime){ $cars->whereBetween('pickup_date',[$pickupDate,$returnDate])>whereBetween('pickup_time',[$pickupTime,$returnTime]) ->whereBetween('return_date',[$pickupDate,$returnDate]) ->whereBetween('return_time',[$pickupTime,$returnTime]); })->get();

but it is not working fine. it give me car that has already reservation it gives me back two cars having reservation 8:00 to 12:00 and 11:00 to 12:00

0 likes
2 replies
crnkovic's avatar

What is the relationship type to the User? How does the cars table look? Are you leveraging Carbon for those date columns?

Please use Github code formatting.

MudassirAbbas's avatar

user and car has many to many relation with pivot table .

Please or to participate in this conversation.