ReviewResource.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class ReviewResource extends JsonResource
  6. {
  7. public function toArray(Request $request): array
  8. {
  9. return [
  10. 'id' => $this->id,
  11. 'schedule_id' => $this->schedule_id,
  12. 'schedule_label' => $this->schedule
  13. ? ($this->schedule->id . ' - ' .
  14. ($this->schedule->client?->user?->name ?? '?') . ' - ' .
  15. ($this->schedule->provider?->user?->name ?? '?') . ' - ' .
  16. ($this->schedule->date?->format('d/m/Y') ?? '?'))
  17. : null,
  18. 'origin' => $this->origin,
  19. 'origin_id' => $this->origin_id,
  20. 'stars' => $this->stars,
  21. 'comment' => $this->comment,
  22. 'reviews_improvements' => $this->whenLoaded('reviewsImprovements', function () {
  23. return $this->reviewsImprovements->map(function ($type) {
  24. return [
  25. 'id' => $type->improvementType->id,
  26. 'description' => $type->improvementType->description,
  27. ];
  28. });
  29. }),
  30. 'created_at' => $this->created_at?->format('Y-m-d H:i'),
  31. 'updated_at' => $this->updated_at?->format('Y-m-d H:i'),
  32. ];
  33. }
  34. }