diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index 394978f1d9d6..37436384c8e0 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -265,9 +265,11 @@ protected function checkDateTimeOrder($format, $first, $second, $operator) $firstDate = $this->getDateTimeWithOptionalFormat($format, $first); if (! $secondDate = $this->getDateTimeWithOptionalFormat($format, $second)) { - $second = $this->getValue($second); + if (is_null($second = $this->getValue($second))) { + return true; + } - $secondDate = is_null($second) ? null : $this->getDateTimeWithOptionalFormat($format, $second); + $secondDate = $this->getDateTimeWithOptionalFormat($format, $second); } return ($firstDate && $secondDate) && ($this->compare($firstDate, $secondDate, $operator)); diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 04d2369f44d1..f9245bdb0049 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -4173,6 +4173,9 @@ public function testBeforeAndAfterWithFormat() $v = new Validator($trans, ['start' => '31/12/2012', 'ends' => null], ['start' => 'date_format:d/m/Y|before:ends', 'ends' => 'date_format:d/m/Y|after:start']); $this->assertTrue($v->fails()); + $v = new Validator($trans, ['start' => '31/12/2012', 'ends' => null], ['start' => 'date_format:d/m/Y|before:ends', 'ends' => 'nullable|date_format:d/m/Y|after:start']); + $this->assertTrue($v->passes()); + $v = new Validator($trans, ['x' => date('d/m/Y')], ['x' => 'date_format:d/m/Y|after:yesterday|before:tomorrow']); $this->assertTrue($v->passes());