I have a car model and an order model, i need a query that will filter the list of cars that are not rented between two dates, i’m lacking the logic to get the answer right what i came up with is this :
$query->whereHas('orders', function ($query) use ($date, $data)
{
$query->whereNotBetween('rental_start_date', $fromDate, $toDate])
->whereNotBetween('rental_end_date', $fromDate, $toDate])
->whereDate('rental_start_date', '<>', $fromDate)
->whereDate('rental_end_date', '<>', $toDate);
}```
2
Answers
Use
whereDoesntHave()
to filter thisI think you can use to filter the list of cars that are not rented between two dates like this:
This query will first get all of the orders that were placed between the two dates. It will then use the whereDoesntHave() method to filter out any cars that have an order in this date range. This will leave you with a list of cars that are not rented between the two dates.