From 2e0dd6aa03082d6260ae4d7fdf3402185e7f6f5e Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Tue, 5 Apr 2016 19:19:58 +0000 Subject: [PATCH] Add after and before to dependent rules array --- src/Illuminate/Validation/Validator.php | 1 + tests/Validation/ValidationValidatorTest.php | 25 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 72bc33e5bec8..631ec8875314 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -174,6 +174,7 @@ class Validator implements ValidatorContract protected $dependentRules = [ 'RequiredWith', 'RequiredWithAll', 'RequiredWithout', 'RequiredWithoutAll', 'RequiredIf', 'RequiredUnless', 'Confirmed', 'Same', 'Different', 'Unique', + 'Before', 'After', ]; /** diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 4a62f1c3c81c..482ef24d21e6 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -2647,6 +2647,31 @@ public function testValidateImplicitEachWithAsterisksRequiredWithoutAll() $this->assertTrue($v->messages()->has('foo.0.bar.1.name')); } + public function testValidateImplicitEachWithAsterisksBeforeAndAfter() + { + $trans = $this->getRealTranslator(); + + $v = new Validator($trans, ['foo' => [ + ['start' => '2016-04-19', 'end' => '2046-04-19'], + ]], ['foo.*.start' => ['before:foo.*.end']]); + $this->assertTrue($v->passes()); + + $v = new Validator($trans, ['foo' => [ + ['start' => '2016-04-19', 'end' => '2046-04-19'], + ]], ['foo.*.end' => ['before:foo.*.start']]); + $this->assertTrue($v->fails()); + + $v = new Validator($trans, ['foo' => [ + ['start' => '2016-04-19', 'end' => '2046-04-19'], + ]], ['foo.*.end' => ['after:foo.*.start']]); + $this->assertTrue($v->passes()); + + $v = new Validator($trans, ['foo' => [ + ['start' => '2016-04-19', 'end' => '2046-04-19'], + ]], ['foo.*.start' => ['after:foo.*.end']]); + $this->assertTrue($v->fails()); + } + public function testValidateEachWithNonIndexedArray() { $trans = $this->getRealTranslator();