Skip to content

Commit f076cd9

Browse files
committed
feat: allow dot notation in arrays validation
1 parent 23c7895 commit f076cd9

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Illuminate/Validation/Validator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,7 @@ public function setRules(array $rules)
12221222
->mapWithKeys(function ($value, $key) {
12231223
return [str_replace('\.', '__dot__'.static::$placeholderHash, $key) => $value];
12241224
})
1225+
->dot()
12251226
->toArray();
12261227

12271228
$this->initialRules = $rules;

tests/Foundation/FoundationFormRequestTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,17 @@ public function testValidatedMethodReturnsTheValidatedDataNestedArrayRules()
7171
$this->assertEquals(['nested' => [['bar' => 'baz'], ['bar' => 'baz2']]], $request->validated());
7272
}
7373

74+
public function testValidatedMethodReturnsTheValidatedDataNestedWildcardArrayRules()
75+
{
76+
$payload = ['nested' => [['bar' => 'baz', 'with' => 'extras'], ['bar' => 'baz2', 'with' => 'extras']]];
77+
78+
$request = $this->createRequest($payload, FoundationTestFormRequestNestedWildcardArrayStub::class);
79+
80+
$request->validateResolved();
81+
82+
$this->assertEquals(['nested' => [['bar' => 'baz'], ['bar' => 'baz2']]], $request->validated());
83+
}
84+
7485
public function testValidatedMethodNotValidateTwice()
7586
{
7687
$payload = ['name' => 'specified', 'with' => 'extras'];
@@ -384,6 +395,25 @@ public function authorize()
384395
}
385396
}
386397

398+
class FoundationTestFormRequestNestedWildcardArrayStub extends FormRequest
399+
{
400+
public function rules()
401+
{
402+
return [
403+
'nested' => [
404+
'*' => [
405+
'bar' => 'required',
406+
],
407+
],
408+
];
409+
}
410+
411+
public function authorize()
412+
{
413+
return true;
414+
}
415+
}
416+
387417
class FoundationTestFormRequestTwiceStub extends FormRequest
388418
{
389419
public static $count = 0;

0 commit comments

Comments
 (0)