PartnerAgreementResource.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Resources;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. use App\Http\Resources\MediaResource;
  7. class PartnerAgreementResource extends JsonResource
  8. {
  9. public function toArray(Request $request): array
  10. {
  11. return [
  12. 'id' => $this->id,
  13. 'company_name' => $this->company_name,
  14. 'cnpj' => $this->cnpj,
  15. 'category_id' => $this->category_id,
  16. 'category' => $this->whenLoaded('category', fn() => new CategoryResource($this->category)),
  17. 'responsible' => $this->responsible,
  18. 'discount_percentage' => $this->discount_percentage,
  19. 'description' => $this->description,
  20. 'email' => $this->email,
  21. 'phone' => $this->phone,
  22. 'whatsapp' => $this->whatsapp,
  23. 'website' => $this->website,
  24. 'address' => $this->address,
  25. 'neighborhood' => $this->neighborhood,
  26. 'city_id' => $this->city_id,
  27. 'city' => $this->whenLoaded('city', fn() => new CityResource($this->city)),
  28. 'state_id' => $this->state_id,
  29. 'state' => $this->whenLoaded('state', fn() => new StateResource($this->state)),
  30. 'zip_code' => $this->zip_code,
  31. 'working_hours' => $this->working_hours,
  32. 'contract_start' => $this->contract_start?->format('Y-m-d'),
  33. 'contract_end' => $this->contract_end?->format('Y-m-d'),
  34. 'status' => $this->status,
  35. 'logo' => $this->whenLoaded('logo', fn() => $this->logo ? new MediaResource($this->logo) : null),
  36. 'media' => $this->whenLoaded('media', fn() => MediaResource::collection($this->media)),
  37. 'services' => $this->whenLoaded('services', fn() => PartnerAgreementServiceResource::collection($this->services)),
  38. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  39. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  40. ];
  41. }
  42. }