PartnerAgreementListResource.php 1.2 KB

1234567891011121314151617181920212223242526272829
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. class PartnerAgreementListResource extends JsonResource
  6. {
  7. public function toArray(Request $request): array
  8. {
  9. return [
  10. 'id' => $this->id,
  11. 'company_name' => $this->company_name,
  12. 'cnpj' => $this->cnpj,
  13. 'responsible' => $this->responsible,
  14. 'email' => $this->email,
  15. 'phone' => $this->phone,
  16. 'category_id' => $this->category_id,
  17. 'category' => $this->whenLoaded('category', fn() => new CategoryResource($this->category)),
  18. 'address' => $this->address,
  19. 'neighborhood' => $this->neighborhood,
  20. 'city' => $this->whenLoaded('city', fn() => new CityResource($this->city)),
  21. 'logo' => $this->whenLoaded('logo', fn() => $this->logo ? ['url' => $this->logo->url] : null),
  22. 'discount_percentage' => $this->discount_percentage,
  23. 'contract_end' => $this->contract_end?->format('Y-m-d'),
  24. ];
  25. }
  26. }