| 123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace App\Http\Resources;
- use Illuminate\Http\Request;
- use Illuminate\Http\Resources\Json\JsonResource;
- class SubmissionResource extends JsonResource
- {
- public function toArray(Request $request): array
- {
- return [
- 'id' => $this->id,
- 'name' => $this->name,
- 'email' => $this->email,
- 'message' => $this->message,
- 'ip_address' => $this->ip_address,
- 'status' => $this->status,
- 'created_at' => $this->created_at->toISOString(),
- 'updated_at' => $this->updated_at->toISOString(),
- 'deleted_at' => $this->deleted_at?->toISOString(),
-
- // Связи (загружаются только если были eager loaded)
- 'comments' => CommentResource::collection($this->whenLoaded('comments')),
- 'tags' => TagResource::collection($this->whenLoaded('tags')),
- 'attachments' => AttachmentResource::collection($this->whenLoaded('attachments')),
-
- // Счетчики
- 'comments_count' => $this->whenCounted('comments'),
- 'tags_count' => $this->whenCounted('tags'),
- ];
- }
- }
|