diff --git a/src/Response.php b/src/Response.php index 55b81fc..d445def 100644 --- a/src/Response.php +++ b/src/Response.php @@ -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( diff --git a/tests/SuccessTest.php b/tests/SuccessTest.php index 168ad3c..86679ab 100644 --- a/tests/SuccessTest.php +++ b/tests/SuccessTest.php @@ -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());