CommentResource.php 737 B

123456789101112131415161718192021222324
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class CommentResource extends JsonResource
  6. {
  7. public function toArray(Request $request): array
  8. {
  9. return [
  10. 'id' => $this->id,
  11. 'submission_id' => $this->submission_id,
  12. 'author' => $this->author,
  13. 'content' => $this->content,
  14. 'created_at' => $this->created_at->toISOString(),
  15. 'updated_at' => $this->updated_at->toISOString(),
  16. 'submission' => new SubmissionResource($this->whenLoaded('submission')),
  17. 'attachments' => AttachmentResource::collection($this->whenLoaded('attachments')),
  18. ];
  19. }
  20. }