translate(); return; } $other = 'startPeriod'; if ('startPeriod' === $attribute) { $other = 'endPeriod'; } $otherValue = request()->get($other); // parse date, twice. try { $left = Carbon::parse($value); $right = Carbon::parse($otherValue); } catch (InvalidDateException $e) { // @phpstan-ignore-line app('log')->error(sprintf('"%s" or "%s" is not a valid date or time: %s', $value, $otherValue, $e->getMessage())); $fail('validation.date_or_time')->translate(); return; } catch (InvalidFormatException $e) { app('log')->error(sprintf('"%s" or "%s" is of an invalid format: %s', $value, $otherValue, $e->getMessage())); $fail('validation.date_or_time')->translate(); return; } // start must be before end. if ('startPeriod' === $attribute) { if ($left->gt($right)) { $fail('validation.date_after')->translate(); } return; } // end must be after start if ($left->lt($right)) { $fail('validation.date_after')->translate(); } } }