Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Fix missing Validation rules not working with nested array #49449

Merged
merged 2 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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