PartnerAgreementResource.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. 'user_id' => $this->user_id,
  14. 'user' => $this->whenLoaded('user', fn() => $this->user ? ['id' => $this->user->id, 'name' => $this->user->name] : null),
  15. 'type' => $this->type,
  16. 'company_name' => $this->company_name,
  17. 'cnpj' => $this->cnpj,
  18. 'category_id' => $this->category_id,
  19. 'category' => $this->whenLoaded('category', fn() => new CategoryResource($this->category)),
  20. 'responsible' => $this->responsible,
  21. 'discount_percentage' => $this->discount_percentage,
  22. 'description' => $this->description,
  23. 'email' => $this->email,
  24. 'phone' => $this->phone,
  25. 'whatsapp' => $this->whatsapp,
  26. 'website' => $this->website,
  27. 'address' => $this->address,
  28. 'neighborhood' => $this->neighborhood,
  29. 'city_id' => $this->city_id,
  30. 'city' => $this->whenLoaded('city', fn() => new CityResource($this->city)),
  31. 'state_id' => $this->state_id,
  32. 'state' => $this->whenLoaded('state', fn() => new StateResource($this->state)),
  33. 'zip_code' => $this->zip_code,
  34. 'working_hours' => $this->working_hours,
  35. 'contract_start' => $this->contract_start?->format('Y-m-d'),
  36. 'contract_end' => $this->contract_end?->format('Y-m-d'),
  37. 'status' => $this->status,
  38. 'logo' => $this->whenLoaded('logo', fn() => $this->logo ? new MediaResource($this->logo) : null),
  39. 'media' => $this->whenLoaded('media', fn() => MediaResource::collection($this->media)),
  40. 'services' => $this->whenLoaded('services', fn() => PartnerAgreementServiceResource::collection($this->services)),
  41. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  42. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  43. ];
  44. }
  45. }