diff --git a/README.md b/README.md index 038cb12..65c1f78 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ as converting and formatting exceptions to JSON responses. ## Talablar (Requirements) -- PHP ^7.4|8.1 +- PHP ^8.1 - Laravel ^10 | ^11 ## Talqinlar mutonosibligi (Version Compatibility) diff --git a/composer.json b/composer.json index 9c90476..35cd56b 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ ], "require": { "php": "^8.1", - "illuminate/contracts": "^v10.48.16" + "illuminate/contracts": "^v10.0.1" }, "require-dev": { "orchestra/testbench": "^8.0", diff --git a/src/Responses/RestResponse.php b/src/Responses/RestResponse.php index 53493a8..87ddca7 100644 --- a/src/Responses/RestResponse.php +++ b/src/Responses/RestResponse.php @@ -2,9 +2,8 @@ namespace Ijodkor\ApiResponse\Responses; +use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Http\JsonResponse; -use Illuminate\Http\Resources\Json\ResourceCollection; -use Illuminate\Pagination\LengthAwarePaginator; use Ijodkor\ApiResponse\Supporters\ListPaginator; trait RestResponse { @@ -104,24 +103,16 @@ protected function noContent(): JsonResponse { /** * Returned paginated response - * @param LengthAwarePaginator|ResourceCollection $data + * @param LengthAwarePaginator $data * @param string $key * @param string|null $message * @return JsonResponse */ - protected function paginated($data, string $key, ?string $message = 'Muvaffaqiyatli'): JsonResponse { - if ($data instanceof LengthAwarePaginator) { - $data = new ListPaginator($data, $key); - } elseif ($data instanceof ResourceCollection) { - $data = new ListPaginator($data, $key); - } - + protected function paginated(LengthAwarePaginator $data, string $key, ?string $message = 'Muvaffaqiyatli'): JsonResponse { return response()->json([ 'status' => true, - 'data' => [ - $key => $data - ], - 'message' => $message, + 'data' => new ListPaginator($data, $key), + 'message' => $message ]); } } diff --git a/src/Supporters/ListPaginator.php b/src/Supporters/ListPaginator.php index e626e08..8b19b06 100644 --- a/src/Supporters/ListPaginator.php +++ b/src/Supporters/ListPaginator.php @@ -3,7 +3,6 @@ namespace Ijodkor\ApiResponse\Supporters; use Illuminate\Contracts\Pagination\LengthAwarePaginator as Paginator; -use Illuminate\Http\Resources\Json\ResourceCollection; use Illuminate\Pagination\LengthAwarePaginator; class ListPaginator extends LengthAwarePaginator { @@ -13,7 +12,7 @@ class ListPaginator extends LengthAwarePaginator { */ private string $key; - public function __construct(Paginator|ResourceCollection $paginator, string $key = "data") { + public function __construct(Paginator $paginator, string $key = "data") { $this->key = $key; $options = ['path' => $paginator->path()];