Answer the question
In order to leave comments, you need to log in
Is it possible to add a condition on the number of child records in whereDoesntHave?
Hello,
Can you please tell me if it is possible to select records in which the number of child records is less than or equal to 1 using whereDoesntHave?
$room = Room::whereDoesntHave('bookings', function($query) use ($request) {
$query->where('end', '>=', $request->start_date);
$query->where('start', '<=', $request->end_date);
}
);
Answer the question
In order to leave comments, you need to log in
Room::whereHas('bookings', function($query) use ($request) {
$query->where('end', '>=', $request->start_date);
$query->where('start', '<=', $request->end_date);
}, '<=', 1)->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question