I am working in an online bike booking system where the customer can book a bike for a particular date-time range. If another customer books the same bike for a specified date-time range, I have to check whether the bike is already booked or not. My database table reservations
looks like this:
id bike_id start_date end_date
1 1 2019-05-04 14:30 2019-05-04 15:30
1 1 2019-05-04 16:30 2019-05-04 18:30
The query:
Reservations::where('yacht_id', $yacht)
->where(function ($query) use ($startTime, $endTime) {
$query->where(function ($query) use ($startTime, $endTime) {
$query->where('book_in', '<', $startTime)
->where('book_out', '>', $startTime);
})
->orWhere(function ($query) use ($startTime, $endTime) {
$query->where('book_in', '>', $endTime)
->where('book_out', '<', $endTime);
});
});
Unfortunately, the code does not seem to work. It does not check the condition properly. How to do the desired check properly using the given inputs?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire