diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index bfff81b645b2..e39f05490641 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -7,6 +7,7 @@ use Countable; use Exception; use DateTimeZone; +use Carbon\Carbon; use RuntimeException; use Illuminate\Support\Arr; use Illuminate\Support\Str; @@ -1425,7 +1426,7 @@ protected function validateBefore($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'before'); - if (! is_string($value) && ! is_numeric($value)) { + if (! is_string($value) && ! is_numeric($value) && ! $value instanceof Carbon) { return false; } @@ -1467,7 +1468,7 @@ protected function validateAfter($attribute, $value, $parameters) { $this->requireParameterCount(1, $parameters, 'after'); - if (! is_string($value) && ! is_numeric($value)) { + if (! is_string($value) && ! is_numeric($value) && ! $value instanceof Carbon) { return false; } diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 009a2c8896c2..3bef7b8fa6b7 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1,6 +1,7 @@ ['2000-01-01']], ['x' => 'Before:2012-01-01']); $this->assertFalse($v->passes()); + $v = new Validator($trans, ['x' => new Carbon('2000-01-01')], ['x' => 'Before:2012-01-01']); + $this->assertTrue($v->passes()); + + $v = new Validator($trans, ['x' => [new Carbon('2000-01-01')]], ['x' => 'Before:2012-01-01']); + $this->assertFalse($v->passes()); + $v = new Validator($trans, ['x' => '2012-01-01'], ['x' => 'After:2000-01-01']); $this->assertTrue($v->passes()); $v = new Validator($trans, ['x' => ['2012-01-01']], ['x' => 'After:2000-01-01']); $this->assertFalse($v->passes()); + $v = new Validator($trans, ['x' => new Carbon('2012-01-01')], ['x' => 'After:2000-01-01']); + $this->assertTrue($v->passes()); + + $v = new Validator($trans, ['x' => [new Carbon('2012-01-01')]], ['x' => 'After:2000-01-01']); + $this->assertFalse($v->passes()); + $v = new Validator($trans, ['start' => '2012-01-01', 'ends' => '2013-01-01'], ['start' => 'After:2000-01-01', 'ends' => 'After:start']); $this->assertTrue($v->passes());