custom rule if hotel room is booked for a certain dates you can't create bookings on that dates
Datepicker::make('checkin_date')
->label('Checkin Date')
->native(false)
->required()
->rule(function ($get) {
return function ($attribute, $value, $fail) use($get) {
$roomId = request()->get('room_id');
$checkinDate = Carbon::parse(request()->get('checkin_date'));
//dd('Closure is executing');
dd([
'roomId' => $roomId,
'checkinDate' => $checkinDate,
'value' => $value,
]);
//dd($get('checkin_date'));
if ($roomId && $checkinDate && Booking::where('room_id', $roomId)
->where(function ($query) use ($checkinDate, $value) {
dd([
'where_condition_checkin_date' => $checkinDate,
'where_condition_value' => $value,
]);
$query->where('checkin_date', '<=', $value)
->where('checkout_date', '>=', $value);
})
->exists()) {
dd('Exists condition is met');
$fail($attribute . ': This room is booked for the selected dates.');
}
};
}),
Datepicker::make('checkin_date')
->label('Checkin Date')
->native(false)
->required()
->rule(function ($get) {
return function ($attribute, $value, $fail) use($get) {
$roomId = request()->get('room_id');
$checkinDate = Carbon::parse(request()->get('checkin_date'));
//dd('Closure is executing');
dd([
'roomId' => $roomId,
'checkinDate' => $checkinDate,
'value' => $value,
]);
//dd($get('checkin_date'));
if ($roomId && $checkinDate && Booking::where('room_id', $roomId)
->where(function ($query) use ($checkinDate, $value) {
dd([
'where_condition_checkin_date' => $checkinDate,
'where_condition_value' => $value,
]);
$query->where('checkin_date', '<=', $value)
->where('checkout_date', '>=', $value);
})
->exists()) {
dd('Exists condition is met');
$fail($attribute . ': This room is booked for the selected dates.');
}
};
}),
0 Replies