2025-01-23 00:45:59 +01:00

64 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Http\Resources;
use App\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Annotations as OA;
/**
* @mixin Category
* @OA\Schema(
* schema="CategoryResource",
* type="object",
* title="Category Resource",
* description="Resource representing a single category",
* @OA\Property(
* property="id",
* type="integer",
* description="ID of the category",
* example=1
* ),
* @OA\Property(
* property="name",
* type="string",
* description="Name of the category",
* example="Technology"
* ),
* @OA\Property(
* property="created_at",
* type="string",
* format="date-time",
* description="Timestamp when the category was created",
* example="2023-12-10T14:17:00Z"
* ),
* @OA\Property(
* property="updated_at",
* type="string",
* format="date-time",
* description="Timestamp when the category was last updated",
* example="2023-12-11T15:20:00Z"
* )
* )
*/
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->toDateTimeString(),
'updated_at' => $this->updated_at->toDateTimeString(),
];
}
}