Custom Validation Rule does not work on every 2nd attempt
Validator::extend('available', function ($attribute, $value, $parameters, $validator) {
$property = Property::find(request('id'));
if ( ! $property) {
return true;
}
foreach ($property->blockedDates()->get() as $booking) {
if (
Carbon::parse(request()->dates['from']) <= Carbon::parse($booking->departure) &&
Carbon::parse(request()->dates['to']) >= Carbon::parse($booking->arrival)
) {
return false;
}
return true;
}
return true;
});
What I'm doing is I'm checking if your requested dates intersected with the property blocked dates.
My problem is that the Custom Validation Rule does not work on every 2nd attempt.
but when I do this. It works on every request
Validator::extend('available', function ($attribute, $value, $parameters, $validator) {
return false;
});
try
Validator::extend('available', function ($attribute, $value, $parameters, $validator) {
$property = Property::find(request('id'));
if ( ! $property) {
return true;
}
foreach ($property->blockedDates()->get() as $booking) {
if (
(Carbon::parse(request()->dates['from']) <= Carbon::parse($booking->departure)) &&
(Carbon::parse(request()->dates['to']) >= Carbon::parse($booking->arrival))
) {
return false;
}
}
return true;
});
Please or to participate in this conversation.