PartnerAgreementListResource.php 1.3 KB

12345678910111213141516171819202122232425262728293031
  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. 'status' => $this->status,
  25. 'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
  26. ];
  27. }
  28. }