#Code validation Booking
$request->validate([
"start_date" => [
"required",
function ($attribute, $value, $fail) use ($request) {
$booking = BookingTransaction::where('meeting_room_id', '=', $request->meeting_room_id)->where([
["start_date", "<=", $request->input('start_date') . ' ' . $request->input('start_time')],
["end_date", ">=", $request->input('start_date') . ' ' . $request->input('start_time')],
])
->orWhere([
["meeting_room_id",'=',$request->meeting_room_id],
["start_date", "<=", $request->input('start_date') . ' ' . $request->input('end_time')],
["end_date", ">=", $request->input('start_date') . ' ' . $request->input('end_time')],
])
->first();
if ($booking) {
$fail(
sprintf("Room meeting has already been booked. Please, try booking again outside this range.",
CarbonCarbon::create($booking->start_date)->format("d M Y H:i"),
CarbonCarbon::create($booking->end_date)->format("d M Y H:i")
)
);
}
},
],
]);
| id | start_date | end_date |
|---|---|---|
| 1 | 2022-10-10 11:00:00 | 2022-10-10 15:00:00 |
#problem
The code above explains the validation if the user adds a booking schedule in the time range between start_date : 2022-10-10 11:00:00 to end_date:
2022-10-10 15:00:00, it will fail,
now I want to validate if the user makes a booking outside the range between start_date:
2022-10-10 11:00:00
until
end_date:
2022-10-10 15:00:00, it will fail,
for example:
if the user makes a booking between:
start_date: 2022-10-10 09:00:00 to end_date: 2022-10-10 16:00:00 will fail ,
how to do above validation ?