Laravel Resource Collection and Pagination

Viewed 81

I'm having trouble bringing model data with pagination, when I return it without going through a resource to transform it, it returns the pagination metadata, but when I use the resource it gets lost, in this example the resource doesn't nothing more and just to illustrate

$clients = (new Client)->whereHasMorph('client', [ Person::class, Company::class ]);

$clients = clientResource::collection($clients->paginate());
return response()->json($clients);
class PessoaResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param Request $request
     * @return array|Arrayable|JsonSerializable
     */
    public function toArray($request): array|JsonSerializable|Arrayable
    {
        return parent::toArray($this);
    }
}

0 Answers
Related