Skip to content

Commit fc3de8d

Browse files
committed
fix: empty data
1 parent 8a490d3 commit fc3de8d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Http/ApiResponseSchema.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class ApiResponseSchema implements Arrayable
2929
*
3030
* @param [type] $result
3131
*/
32-
public function __construct($result = null)
32+
public function __construct(mixed $result)
3333
{
3434
/**
3535
* @see \Illuminate\Database\Eloquent\Collection
@@ -128,9 +128,11 @@ public function getSuccess(): bool
128128
* @param [type] $data
129129
* @return void
130130
*/
131-
public function setResult($data = null): void
131+
public function setResult(mixed $data): void
132132
{
133-
if ($data instanceof AbstractPaginator || $data instanceof AbstractCursorPaginator) {
133+
if ($data instanceof \ArrayObject && $data->count() === 0) {
134+
//JsonResponse will set data to empty ArrayObject so do nothing
135+
} else if ($data instanceof AbstractPaginator || $data instanceof AbstractCursorPaginator) {
134136
$this->resultType = 'collection';
135137
$this->result = AnonymousResource::collection($data);
136138
} elseif ($data instanceof Collection || $data instanceof ResourceCollection) {
@@ -156,7 +158,6 @@ public function setResult($data = null): void
156158
$this->resultType = 'string';
157159
$this->message = $data;
158160
} else {
159-
// dd(gettype($data));
160161
if (gettype($data) !== 'NULL') {
161162
$this->resultType = gettype($data);
162163
}

0 commit comments

Comments
 (0)