58 lines
2.2 KiB
PHP
58 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class TestResource extends JsonResource
|
|
{
|
|
/**
|
|
* @OA\Schema(
|
|
* schema="TestResource",
|
|
* type="object",
|
|
* title="Test",
|
|
* description="Test resource",
|
|
* @OA\Property(property="id", type="integer", example=1),
|
|
* @OA\Property(property="title", type="string", example="Sample Test"),
|
|
* @OA\Property(property="description", type="string", nullable=true, example="Optional description"),
|
|
*
|
|
* @OA\Property(property="category_id", type="integer", nullable=true, example=3),
|
|
* @OA\Property(property="category", ref="#/components/schemas/CategoryResource"),
|
|
*
|
|
* @OA\Property(
|
|
* property="questions",
|
|
* type="array",
|
|
* @OA\Items(ref="#/components/schemas/QuestionResource")
|
|
* ),
|
|
*
|
|
* @OA\Property(property="author_id", type="integer", nullable=true, example=2),
|
|
* @OA\Property(property="author", ref="#/components/schemas/UserResource"),
|
|
*
|
|
* @OA\Property(property="closed_at", type="string", format="date-time", nullable=true, example="2025-11-11T10:30:00Z"),
|
|
* @OA\Property(property="created_at", type="string", format="date-time", example="2025-11-11T10:00:00Z"),
|
|
* @OA\Property(property="updated_at", type="string", format="date-time", example="2025-11-11T10:15:00Z")
|
|
* )
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => $this->title,
|
|
'description' => $this->description,
|
|
|
|
'category_id' => $this->category_id,
|
|
'category' => new CategoryResource($this->whenLoaded('category')),
|
|
|
|
'questions' => QuestionResource::collection($this->whenLoaded('questions')),
|
|
|
|
'author_id' => $this->author_id,
|
|
'author' => new UserResource($this->whenLoaded('author')),
|
|
|
|
'closed_at' => $this->closed_at,
|
|
'created_at' => $this->created_at,
|
|
'updated_at' => $this->updated_at,
|
|
];
|
|
}
|
|
}
|