37 lines
1.0 KiB
PHP
37 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
|
|
class PersonCollection extends ResourceCollection
|
|
{
|
|
/**
|
|
* Transform the resource collection into an array.
|
|
*
|
|
* @return array<int|string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'data' => $this->collection->map(function ($person) {
|
|
return new PersonResource($person);
|
|
}),
|
|
'meta' => [
|
|
'total' => $this->total(),
|
|
'count' => $this->count(),
|
|
'per_page' => $this->perPage(),
|
|
'current_page' => $this->currentPage(),
|
|
'last_page' => $this->lastPage(),
|
|
],
|
|
'links' => [
|
|
'first' => $this->url(1),
|
|
'last' => $this->url($this->lastPage()),
|
|
'prev' => $this->previousPageUrl(),
|
|
'next' => $this->nextPageUrl(),
|
|
],
|
|
];
|
|
}
|
|
}
|