63 lines
1.6 KiB
PHP
63 lines
1.6 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace App\Http\Resources;
|
||
|
|
||
|
use App\Models\Comment;
|
||
|
use Illuminate\Http\Request;
|
||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||
|
use OpenApi\Annotations as OA;
|
||
|
|
||
|
/**
|
||
|
* @mixin Comment
|
||
|
* @OA\Schema(
|
||
|
* schema="CommentResource",
|
||
|
* type="object",
|
||
|
* title="Comment Resource",
|
||
|
* description="Resource representing a single comment",
|
||
|
* @OA\Property(
|
||
|
* property="id",
|
||
|
* type="integer",
|
||
|
* description="ID of the comment",
|
||
|
* example=1
|
||
|
* ),
|
||
|
* @OA\Property(
|
||
|
* property="content",
|
||
|
* type="string",
|
||
|
* description="Content of the comment",
|
||
|
* example="This is a sample comment."
|
||
|
* ),
|
||
|
* @OA\Property(
|
||
|
* property="created_at",
|
||
|
* type="string",
|
||
|
* format="date-time",
|
||
|
* description="Timestamp when the comment was created",
|
||
|
* example="2023-12-10T15:24:00Z"
|
||
|
* ),
|
||
|
* @OA\Property(
|
||
|
* property="updated_at",
|
||
|
* type="string",
|
||
|
* format="date-time",
|
||
|
* description="Timestamp when the comment was last updated",
|
||
|
* example="2023-12-10T16:30:00Z"
|
||
|
* )
|
||
|
* )
|
||
|
*/
|
||
|
class CommentResource extends JsonResource
|
||
|
{
|
||
|
/** Transform the resource into an array.
|
||
|
*
|
||
|
* @return array<string, mixed>
|
||
|
*/
|
||
|
public function toArray(Request $request): array
|
||
|
{
|
||
|
return [
|
||
|
'id' => $this->id,
|
||
|
'content' => $this->content,
|
||
|
'created_at' => $this->created_at->toDateTimeString(),
|
||
|
'updated_at' => $this->updated_at->toDateTimeString(),
|
||
|
];
|
||
|
}
|
||
|
}
|