Skip to content

Commit e850bcd

Browse files
authored
[9.x] Change default behavior of unvalidated array keys (#40368)
* chnage default behavior * update test
1 parent 1eb0ac8 commit e850bcd

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/Illuminate/Validation/Factory.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class Factory implements FactoryContract
7171
*
7272
* @var bool
7373
*/
74-
protected $excludeUnvalidatedArrayKeys;
74+
protected $excludeUnvalidatedArrayKeys = true;
7575

7676
/**
7777
* The Validator resolver instance.
@@ -249,7 +249,17 @@ public function replacer($rule, $replacer)
249249
}
250250

251251
/**
252-
* Indicate that unvalidated array keys should be excluded, even if the parent array was validated.
252+
* Indicate that unvalidated array keys should be included in validated data when the parent array is validated.
253+
*
254+
* @return void
255+
*/
256+
public function includeUnvalidatedArrayKeys()
257+
{
258+
$this->excludeUnvalidatedArrayKeys = false;
259+
}
260+
261+
/**
262+
* Indicate that unvalidated array keys should be excluded from the validated data, even if the parent array was validated.
253263
*
254264
* @return void
255265
*/

tests/Validation/ValidationValidatorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6727,6 +6727,7 @@ public function testExcludingArrays()
67276727
['users' => [['name' => 'Mohamed', 'location' => 'cairo']]],
67286728
['users' => 'array', 'users.*.name' => 'string']
67296729
);
6730+
$validator->excludeUnvalidatedArrayKeys = false;
67306731
$this->assertTrue($validator->passes());
67316732
$this->assertSame(['users' => [['name' => 'Mohamed', 'location' => 'cairo']]], $validator->validated());
67326733

0 commit comments

Comments
 (0)