Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.1] Bring back support for Carbon instances to Before and After validators #13494

Merged
merged 3 commits into from
May 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Countable;
use Exception;
use DateTimeZone;
use Carbon\Carbon;
use RuntimeException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
13 changes: 13 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Mockery as m;
use Carbon\Carbon;
use Illuminate\Validation\Validator;
use Symfony\Component\HttpFoundation\File\File;

Expand Down Expand Up @@ -1359,12 +1360,24 @@ public function testBeforeAndAfter()
$v = new Validator($trans, ['x' => ['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());

Expand Down