Skip to content

Commit

Permalink
[Fix] Arr::forget() for nested ArrayAccess (laravel#42142)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjokkateer authored and chu121su12 committed Apr 29, 2022
1 parent d4ae818 commit 058bb56
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ public static function forget(&$array, $keys)
while (count($parts) > 1) {
$part = array_shift($parts);

if (isset($array[$part]) && is_array($array[$part])) {
if (isset($array[$part]) && static::accessible($array[$part])) {
$array = &$array[$part];
} else {
continue 2;
Expand Down
27 changes: 27 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3515,6 +3515,33 @@ public function testPullRemovesItemFromCollection()
$this->assertEquals([1 => 'bar'], $c->all());
}

public function testPullRemovesItemFromNestedCollection()
{
$nestedCollection = new Collection([
new Collection([
'value',
new Collection([
'bar' => 'baz',
'test' => 'value',
]),
]),
'bar',
]);

$nestedCollection->pull('0.1.test');

$actualArray = $nestedCollection->toArray();
$expectedArray = [
[
'value',
['bar' => 'baz'],
],
'bar',
];

$this->assertEquals($expectedArray, $actualArray);
}

public function testPullReturnsDefault()
{
$c = new Collection([]);
Expand Down

0 comments on commit 058bb56

Please sign in to comment.