ReviewDetailResource.php 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class ReviewDetailResource extends JsonResource
  6. {
  7. public function toArray(Request $request): array
  8. {
  9. $schedule = $this->schedule;
  10. $customSchedule = $schedule?->customSchedule;
  11. $address = $schedule?->address;
  12. return [
  13. 'id' => $this->id,
  14. 'origin' => $this->origin,
  15. 'origin_id' => $this->origin_id,
  16. 'stars' => $this->stars,
  17. 'comment' => $this->comment,
  18. 'created_at' => $this->created_at?->format('Y-m-d H:i'),
  19. 'improvements' => $this->whenLoaded('improvements', function () {
  20. return $this->improvements->map(fn($imp) => [
  21. 'id' => $imp->id,
  22. 'description' => $imp->description,
  23. ]);
  24. }),
  25. 'schedule' => $schedule ? [
  26. 'id' => $schedule->id,
  27. 'schedule_type' => $schedule->schedule_type,
  28. 'status' => $schedule->status,
  29. 'date' => $schedule->date?->format('d/m/Y'),
  30. 'start_time' => $schedule->start_time,
  31. 'end_time' => $schedule->end_time,
  32. 'period_type' => $schedule->period_type,
  33. 'total_amount' => $schedule->total_amount,
  34. 'code' => $schedule->code,
  35. 'client' => $schedule->client ? [
  36. 'id' => $schedule->client->id,
  37. 'name' => $schedule->client->user?->name,
  38. 'email' => $schedule->client->user?->email,
  39. 'phone' => $schedule->client->user?->phone,
  40. ] : null,
  41. 'provider' => $schedule->provider ? [
  42. 'id' => $schedule->provider->id,
  43. 'name' => $schedule->provider->user?->name,
  44. 'email' => $schedule->provider->user?->email,
  45. 'phone' => $schedule->provider->user?->phone,
  46. ] : null,
  47. 'address' => $address ? [
  48. 'street' => $address->street,
  49. 'number' => $address->number,
  50. 'complement' => $address->complement,
  51. 'neighborhood' => $address->neighborhood,
  52. 'city' => $address->city?->name,
  53. 'state' => $address->state?->name,
  54. ] : null,
  55. 'custom_schedule' => $customSchedule ? [
  56. 'address_type' => $customSchedule->address_type,
  57. 'service_type' => $customSchedule->serviceType?->description,
  58. 'specialities' => $customSchedule->specialities
  59. ? $customSchedule->specialities->map(fn($s) => [
  60. 'id' => $s->id,
  61. 'description' => $s->description,
  62. ])
  63. : [],
  64. 'min_price' => $customSchedule->min_price,
  65. 'max_price' => $customSchedule->max_price,
  66. 'offers_meal' => $customSchedule->offers_meal,
  67. 'description' => $customSchedule->description,
  68. ] : null,
  69. ] : null,
  70. ];
  71. }
  72. }