SupportRequestResource.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. /**
  35. * @param \Illuminate\Database\Eloquent\Collection<SupportRequest> $resource
  36. * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<SupportRequestResource>
  37. */
  38. public static function collection($resource): AnonymousResourceCollection
  39. {
  40. return parent::collection($resource);
  41. }
  42. }