55 lines
1.2 KiB
PHP
55 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
/**
|
|
* @OA\Schema(
|
|
* schema="CategoryResource",
|
|
* type="object",
|
|
* title="Category",
|
|
* description="Category resource with dynamic count",
|
|
* @OA\Property(
|
|
* property="id",
|
|
* type="integer",
|
|
* example=1
|
|
* ),
|
|
* @OA\Property(
|
|
* property="name",
|
|
* type="string",
|
|
* example="Books"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="created_at",
|
|
* type="string",
|
|
* format="date-time",
|
|
* example="2025-11-10T18:00:00Z"
|
|
* ),
|
|
* @OA\Property(
|
|
* property="count",
|
|
* type="integer",
|
|
* example=5,
|
|
* description="Dynamic count of related items"
|
|
* )
|
|
* )
|
|
*/
|
|
class CategoryResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'name' => $this->name,
|
|
'created_at' => $this->created_at,
|
|
'count' => $this->count ?? 0
|
|
];
|
|
}
|
|
}
|