Skip to content

Commit d112054

Browse files
authored
Merge pull request #13 from kodepandai/support-model
refactor: change type data Collection to Arrayable
2 parents 2b89ddc + 916dbdc commit d112054

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/ApiResponse.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace KodePandai\ApiResponse;
44

5+
use Illuminate\Contracts\Support\Arrayable;
56
use Illuminate\Contracts\Support\Responsable;
67
use Illuminate\Http\JsonResponse;
78
use Illuminate\Http\Request;
89
use Illuminate\Http\Resources\Json\JsonResource;
910
use Illuminate\Http\Resources\Json\ResourceCollection;
1011
use Illuminate\Http\Response;
11-
use Illuminate\Support\Collection;
1212
use Illuminate\Support\Facades\Validator;
1313
use Illuminate\Support\Fluent;
1414
use InvalidArgumentException;
@@ -62,12 +62,12 @@ public function addHeaders(array $headers): self
6262
public function toResponse($request): JsonResponse
6363
{
6464
return (new JsonResponse([
65-
'success' => $this->isSuccess,
66-
'title' => $this->title,
67-
'message' => $this->message,
68-
'data' => $this->data,
69-
'errors' => $this->errors,
70-
]))
65+
'success' => $this->isSuccess,
66+
'title' => $this->title,
67+
'message' => $this->message,
68+
'data' => $this->data,
69+
'errors' => $this->errors,
70+
]))
7171
->setStatusCode($this->statusCode)
7272
->withHeaders($this->headers);
7373
}
@@ -83,7 +83,7 @@ public static function create(): self
8383
/**
8484
* Return a success api response.
8585
*
86-
* @param array|Collection|JsonResource|ResourceCollection $data
86+
* @param array|Arrayable|JsonResource|ResourceCollection $data
8787
*/
8888
public static function success($data = []): self
8989
{
@@ -135,10 +135,10 @@ public static function validateOrFail(
135135
}
136136

137137
/**
138-
* Add data to response and transform according to its type.
139-
*
140-
* @param array|Collection|JsonResource|ResourceCollection $data
141-
*/
138+
* Add data to response and transform according to its type.
139+
*
140+
* @param array|Arrayable|JsonResource|ResourceCollection $data
141+
*/
142142
public function data($data): self
143143
{
144144
if (is_array($data)) {
@@ -150,7 +150,7 @@ public function data($data): self
150150
} elseif ($data instanceof JsonResource) {
151151
$this->attributes['data'] = json_decode($data->toJson(), true);
152152
//.
153-
} elseif ($data instanceof Collection) {
153+
} elseif ($data instanceof Arrayable) {
154154
$this->attributes['data'] = $data->toArray();
155155
//.
156156
} else {

0 commit comments

Comments
 (0)