Skip to content

Commit

Permalink
[10.x] Fix missing Validation rules not working with nested array (#4…
Browse files Browse the repository at this point in the history
…9449)

* support missing rule with nested array data

* fix style
  • Loading branch information
aabadawy authored Dec 21, 2023
1 parent 0c68ae1 commit d4b727b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ class Validator implements ValidatorContract
'ProhibitedIf',
'ProhibitedUnless',
'Prohibits',
'MissingIf',
'MissingUnless',
'MissingWith',
'MissingWithAll',
'Same',
'Unique',
];
Expand Down
16 changes: 16 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit d4b727b

Please sign in to comment.