49 lines
1.5 KiB
PHP
49 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Client;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
|
|
class ClientCollection extends ResourceCollection
|
|
{
|
|
/**
|
|
* Transform the resource collection into an array.
|
|
*
|
|
* @return array<int|string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'data' => $this->collection,
|
|
'meta' => [
|
|
'total' => $this->total(),
|
|
'per_page' => $this->perPage(),
|
|
'current_page' => $this->currentPage(),
|
|
'last_page' => $this->lastPage(),
|
|
'from' => $this->firstItem(),
|
|
'to' => $this->lastItem(),
|
|
'stats' => [
|
|
'active' => $this->collection->where('is_active', true)->count(),
|
|
'inactive' => $this->collection->where('is_active', false)->count(),
|
|
'by_type' => $this->collection->groupBy('client_category_id')->map->count(),
|
|
],
|
|
],
|
|
'links' => [
|
|
'first' => $this->url(1),
|
|
'last' => $this->url($this->lastPage()),
|
|
'prev' => $this->previousPageUrl(),
|
|
'next' => $this->nextPageUrl(),
|
|
],
|
|
];
|
|
}
|
|
|
|
public function with(Request $request): array
|
|
{
|
|
return [
|
|
'status' => 'success',
|
|
'message' => 'Clients récupérés avec succès',
|
|
];
|
|
}
|
|
}
|