Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.6] Fix issue with Resources when loading a single MergeValue with an associative array #23414

Merged
merged 2 commits into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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