Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6118315

Browse files
committed
Merge pull request laravel#1824 from shachibista/master
Added ability to reference fields in before and after validators
2 parents b088a2e + b9aee2b commit 6118315

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/Illuminate/Validation/Validator.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,14 @@ protected function validateDateFormat($attribute, $value, $parameters)
944944
*/
945945
protected function validateBefore($attribute, $value, $parameters)
946946
{
947-
return strtotime($value) < strtotime($parameters[0]);
947+
if ( ! ($date = strtotime($parameters[0])))
948+
{
949+
return strtotime($value) < strtotime($this->getValue($parameters[0]));
950+
}
951+
else
952+
{
953+
return strtotime($value) < $date;
954+
}
948955
}
949956

950957
/**
@@ -957,7 +964,14 @@ protected function validateBefore($attribute, $value, $parameters)
957964
*/
958965
protected function validateAfter($attribute, $value, $parameters)
959966
{
960-
return strtotime($value) > strtotime($parameters[0]);
967+
if ( ! ($date = strtotime($parameters[0])))
968+
{
969+
return strtotime($value) > strtotime($this->getValue($parameters[0]));
970+
}
971+
else
972+
{
973+
return strtotime($value) > $date;
974+
}
961975
}
962976

963977
/**

tests/Validation/ValidationValidatorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,18 @@ public function testBeforeAndAfter()
712712

713713
$v = new Validator($trans, array('x' => '2012-01-01'), array('x' => 'After:2000-01-01'));
714714
$this->assertTrue($v->passes());
715+
716+
$v = new Validator($trans, array('start' => '2012-01-01', 'ends' => '2013-01-01'), array('start' => 'After:2000-01-01', 'ends' => 'After:start'));
717+
$this->assertTrue($v->passes());
718+
719+
$v = new Validator($trans, array('start' => '2012-01-01', 'ends' => '2000-01-01'), array('start' => 'After:2000-01-01', 'ends' => 'After:start'));
720+
$this->assertTrue($v->fails());
721+
722+
$v = new Validator($trans, array('start' => '2012-01-01', 'ends' => '2013-01-01'), array('start' => 'Before:ends', 'ends' => 'After:start'));
723+
$this->assertTrue($v->passes());
724+
725+
$v = new Validator($trans, array('start' => '2012-01-01', 'ends' => '2000-01-01'), array('start' => 'Before:ends', 'ends' => 'After:start'));
726+
$this->assertTrue($v->fails());
715727
}
716728

717729

0 commit comments

Comments
 (0)