SupportRequestResource.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Http\Resources;
  3. use App\Models\SupportRequest;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  6. use Illuminate\Http\Resources\Json\JsonResource;
  7. class SupportRequestResource extends JsonResource
  8. {
  9. /**
  10. * Transform the resource into an array.
  11. *
  12. * @return array<string, mixed>
  13. */
  14. public function toArray(Request $request): array
  15. {
  16. return [
  17. 'id' => $this->id,
  18. 'user_id' => $this->user_id,
  19. 'user_type' => $this->user_type,
  20. 'name' => $this->name,
  21. 'email' => $this->email,
  22. 'phone' => $this->phone,
  23. 'category' => $this->category,
  24. 'title' => $this->title,
  25. 'message' => $this->message,
  26. 'status' => $this->status?->value,
  27. 'handled_by' => $this->handled_by,
  28. 'handler' => $this->whenLoaded('handler', fn () => $this->handler?->name),
  29. 'resolved_at' => $this->resolved_at?->format('d/m/Y H:i'),
  30. 'created_at' => $this->created_at?->format('d/m/Y H:i'),
  31. 'updated_at' => $this->updated_at?->format('d/m/Y H:i'),
  32. ];
  33. }
  34. public static function collection($resource): AnonymousResourceCollection
  35. {
  36. return parent::collection($resource);
  37. }
  38. }