Skip to content

Commit d4b727b

Browse files
authored
[10.x] Fix missing Validation rules not working with nested array (#49449)
* support missing rule with nested array data * fix style
1 parent 0c68ae1 commit d4b727b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Illuminate/Validation/Validator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ class Validator implements ValidatorContract
265265
'ProhibitedIf',
266266
'ProhibitedUnless',
267267
'Prohibits',
268+
'MissingIf',
269+
'MissingUnless',
270+
'MissingWith',
271+
'MissingWithAll',
268272
'Same',
269273
'Unique',
270274
];

tests/Validation/ValidationValidatorTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,6 +2498,10 @@ public function count(): int
24982498

24992499
$v = new Validator($trans, ['foo' => 'foo', 'bar' => '2'], ['foo' => 'missing_if:bar,1']);
25002500
$this->assertTrue($v->passes());
2501+
2502+
$v = new Validator($trans,['foo' => [0 => ['bar' => 1, 'baz' => 'should be missing']]], ['foo.*.baz' => 'missing_if:foo.*.bar,1']);
2503+
$this->assertTrue($v->fails());
2504+
$this->assertSame('The foo.0.baz field must be missing when foo.0.bar is 1.', $v->errors()->first('foo.0.baz'));
25012505
}
25022506

25032507
public function testValidateMissingUnless()
@@ -2537,6 +2541,10 @@ public function count(): int
25372541

25382542
$v = new Validator($trans, ['foo' => 'foo', 'bar' => '1'], ['foo' => 'missing_unless:bar,1']);
25392543
$this->assertTrue($v->passes());
2544+
2545+
$v = new Validator($trans,['foo' => [0 => ['bar' => 0, 'baz' => 'should be missing']]], ['foo.*.baz' => 'missing_unless:foo.*.bar,1']);
2546+
$this->assertTrue($v->fails());
2547+
$this->assertSame('The foo.0.baz field must be missing unless foo.0.bar is 1.', $v->errors()->first('foo.0.baz'));
25402548
}
25412549

25422550
public function testValidateMissingWith()
@@ -2579,6 +2587,10 @@ public function count(): int
25792587

25802588
$v = new Validator($trans, ['foo' => 'foo', 'qux' => '1'], ['foo' => 'missing_with:baz,bar']);
25812589
$this->assertTrue($v->passes());
2590+
2591+
$v = new Validator($trans,['foo' => [0 => ['bar' => 1, 'baz' => 'should be missing']]], ['foo.*.baz' => 'missing_with:foo.*.bar,foo.*.fred']);
2592+
$this->assertTrue($v->fails());
2593+
$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'));
25822594
}
25832595

25842596
public function testValidateMissingWithAll()
@@ -2621,6 +2633,10 @@ public function count(): int
26212633

26222634
$v = new Validator($trans, ['foo' => [], 'bar' => '2', 'qux' => '2'], ['foo' => 'missing_with_all:baz,bar']);
26232635
$this->assertTrue($v->passes());
2636+
2637+
$v = new Validator($trans,['foo' => [0 => ['bar' => 1,'fred' => 2, 'baz' => 'should be missing']]], ['foo.*.baz' => 'missing_with_all:foo.*.bar,foo.*.fred']);
2638+
$this->assertTrue($v->fails());
2639+
$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'));
26242640
}
26252641

26262642
public function testValidateDeclinedIf()

0 commit comments

Comments
 (0)