Skip to content

Commit

Permalink
[5.6] Fix issue with Resources when loading a single MergeValue with …
Browse files Browse the repository at this point in the history
…an associative array (#23414)

*          fix issue with resources loading assoc marge values

*    fix style
  • Loading branch information
themsaid authored and taylorotwell committed Mar 6, 2018
1 parent 6330c10 commit a4e414f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ protected function removeMissingValues($data, $numericKeys = false)
}
}

return $numericKeys ? array_values($data) : $data;
return ! empty($data) && is_numeric(array_keys($data)[0])
? array_values($data) : $data;
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/Integration/Http/ResourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,26 @@ public function test_original_on_response_is_collection_of_model_when_collection
});
}

public function test_leading_merge__keyed_value_is_merged_correctly()
{
$filter = new class {
use ConditionallyLoadsAttributes;

public function work()
{
return $this->filter([
new MergeValue(['name' => 'mohamed', 'location' => 'hurghada']),
]);
}
};

$results = $filter->work();

$this->assertEquals([
'name' => 'mohamed', 'location' => 'hurghada',
], $results);
}

public function test_leading_merge_value_is_merged_correctly()
{
$filter = new class {
Expand Down

0 comments on commit a4e414f

Please sign in to comment.