Skip to content

Commit

Permalink
revert: resource collection 结构 (close: #56
Browse files Browse the repository at this point in the history
  • Loading branch information
jiannei committed Nov 17, 2021
1 parent e4f8d3f commit b3ccfc8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,13 +344,12 @@ protected function formatPaginatedData(array $paginated)
*/
protected function formatResourceCollectionResponse($resource, string $message = '', int $code = 200, array $headers = [], int $option = 0)
{
$data = array_merge_recursive(['data' => $resource->resolve(request())], $resource->with(request()), $resource->additional);
if ($resource->resource instanceof AbstractPaginator) {
$paginated = $resource->resource->toArray();
$paginationInformation = $this->formatPaginatedData($paginated);

$data = array_merge_recursive(['data' => $resource->resolve(request())], $resource->with(request()), $resource->additional, $paginationInformation);
} else {
$data = array_merge_recursive($resource->resolve(request()), $resource->with(request()), $resource->additional);
$data = array_merge_recursive($data, $paginationInformation);
}

return tap(
Expand Down
2 changes: 1 addition & 1 deletion tests/SuccessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public function testSuccessWithCollectionData()
'status' => 'success',
'code' => 200,
'message' => ResponseCodeEnum::fromValue(200)->description,
'data' => $data,
'data' => ['data' => $data],
'error' => (object) [],
]);
$this->assertJsonStringEqualsJsonString($expectedJson, $response->getContent());
Expand Down

0 comments on commit b3ccfc8

Please sign in to comment.