PartnerAgreementResource.php 2.5 KB

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