Skip to content

Commit

Permalink
Pass default into recursive call of data_get
Browse files Browse the repository at this point in the history
  • Loading branch information
icexist committed Aug 23, 2024
1 parent c50ee30 commit e4dec12
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function data_get($target, $key, $default = null)
$result = [];

foreach ($target as $item) {
$result[] = data_get($item, $key);
$result[] = data_get($item, $key, $default);
}

return in_array('*', $key) ? Arr::collapse($result) : $result;
Expand Down
6 changes: 3 additions & 3 deletions tests/Support/SupportHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ public function testDataGetWithNestedArrays()
]);

$this->assertEquals(['taylor', 'abigail', 'dayle'], data_get($array, '*.name'));
$this->assertEquals(['[email protected]', null, null], data_get($array, '*.email', 'irrelevant'));
$this->assertEquals(['[email protected]', 'default', 'default'], data_get($array, '*.email', 'default'));

$this->assertEquals(['taylor', 'abigail', 'dayle'], data_get($arrayIterable, '*.name'));
$this->assertEquals(['[email protected]', null, null], data_get($arrayIterable, '*.email', 'irrelevant'));
$this->assertEquals(['[email protected]', 'default', 'default'], data_get($arrayIterable, '*.email', 'default'));

$array = [
'users' => [
Expand All @@ -223,7 +223,7 @@ public function testDataGetWithNestedArrays()
];

$this->assertEquals(['taylor', 'abigail', 'dayle'], data_get($array, 'users.*.first'));
$this->assertEquals(['[email protected]', null, null], data_get($array, 'users.*.email', 'irrelevant'));
$this->assertEquals(['[email protected]', 'default', 'default'], data_get($array, 'users.*.email', 'default'));
$this->assertSame('not found', data_get($array, 'posts.*.date', 'not found'));
$this->assertNull(data_get($array, 'posts.*.date'));
}
Expand Down

0 comments on commit e4dec12

Please sign in to comment.