diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 3894e6e141ba..35d18149af79 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -265,6 +265,10 @@ class Validator implements ValidatorContract 'ProhibitedIf', 'ProhibitedUnless', 'Prohibits', + 'MissingIf', + 'MissingUnless', + 'MissingWith', + 'MissingWithAll', 'Same', 'Unique', ]; diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 6ce65cc2b6d5..ce48adf6c196 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -2498,6 +2498,10 @@ public function count(): int $v = new Validator($trans, ['foo' => 'foo', 'bar' => '2'], ['foo' => 'missing_if:bar,1']); $this->assertTrue($v->passes()); + + $v = new Validator($trans,['foo' => [0 => ['bar' => 1, 'baz' => 'should be missing']]], ['foo.*.baz' => 'missing_if:foo.*.bar,1']); + $this->assertTrue($v->fails()); + $this->assertSame('The foo.0.baz field must be missing when foo.0.bar is 1.', $v->errors()->first('foo.0.baz')); } public function testValidateMissingUnless() @@ -2537,6 +2541,10 @@ public function count(): int $v = new Validator($trans, ['foo' => 'foo', 'bar' => '1'], ['foo' => 'missing_unless:bar,1']); $this->assertTrue($v->passes()); + + $v = new Validator($trans,['foo' => [0 => ['bar' => 0, 'baz' => 'should be missing']]], ['foo.*.baz' => 'missing_unless:foo.*.bar,1']); + $this->assertTrue($v->fails()); + $this->assertSame('The foo.0.baz field must be missing unless foo.0.bar is 1.', $v->errors()->first('foo.0.baz')); } public function testValidateMissingWith() @@ -2579,6 +2587,10 @@ public function count(): int $v = new Validator($trans, ['foo' => 'foo', 'qux' => '1'], ['foo' => 'missing_with:baz,bar']); $this->assertTrue($v->passes()); + + $v = new Validator($trans,['foo' => [0 => ['bar' => 1, 'baz' => 'should be missing']]], ['foo.*.baz' => 'missing_with:foo.*.bar,foo.*.fred']); + $this->assertTrue($v->fails()); + $this->assertSame('The foo.0.baz field must be missing when foo.0.bar / foo.0.fred is present.', $v->errors()->first('foo.0.baz')); } public function testValidateMissingWithAll() @@ -2621,6 +2633,10 @@ public function count(): int $v = new Validator($trans, ['foo' => [], 'bar' => '2', 'qux' => '2'], ['foo' => 'missing_with_all:baz,bar']); $this->assertTrue($v->passes()); + + $v = new Validator($trans,['foo' => [0 => ['bar' => 1,'fred' => 2, 'baz' => 'should be missing']]], ['foo.*.baz' => 'missing_with_all:foo.*.bar,foo.*.fred']); + $this->assertTrue($v->fails()); + $this->assertSame('The foo.0.baz field must be missing when foo.0.bar / foo.0.fred are present.', $v->errors()->first('foo.0.baz')); } public function testValidateDeclinedIf()