Skip to content

Commit

Permalink
Extra data error fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
yetakchi committed Jul 26, 2024
1 parent 31957c8 commit 74fc312
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
],
"require": {
"php": "^8.1",
"illuminate/contracts": "^v10.48.16"
"illuminate/contracts": "^v10.0.1"
},
"require-dev": {
"orchestra/testbench": "^8.0",
Expand Down
19 changes: 5 additions & 14 deletions src/Responses/RestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
]);
}
}
3 changes: 1 addition & 2 deletions src/Supporters/ListPaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()];
Expand Down

0 comments on commit 74fc312

Please sign in to comment.