SubmissionResource.php 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class SubmissionResource extends JsonResource
  6. {
  7. public function toArray(Request $request): array
  8. {
  9. return [
  10. 'id' => $this->id,
  11. 'name' => $this->name,
  12. 'email' => $this->email,
  13. 'message' => $this->message,
  14. 'ip_address' => $this->ip_address,
  15. 'status' => $this->status,
  16. 'created_at' => $this->created_at->toISOString(),
  17. 'updated_at' => $this->updated_at->toISOString(),
  18. 'deleted_at' => $this->deleted_at?->toISOString(),
  19. // Связи (загружаются только если были eager loaded)
  20. 'comments' => CommentResource::collection($this->whenLoaded('comments')),
  21. 'tags' => TagResource::collection($this->whenLoaded('tags')),
  22. 'attachments' => AttachmentResource::collection($this->whenLoaded('attachments')),
  23. // Счетчики
  24. 'comments_count' => $this->whenCounted('comments'),
  25. 'tags_count' => $this->whenCounted('tags'),
  26. ];
  27. }
  28. }