PartnerAgreementListResource.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <?php
  2. namespace App\Http\Resources;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Resources\Json\JsonResource;
  5. use Illuminate\Support\Facades\Storage;
  6. class PartnerAgreementListResource extends JsonResource
  7. {
  8. public function toArray(Request $request): array
  9. {
  10. return [
  11. 'id' => $this->id,
  12. 'company_name' => $this->company_name,
  13. 'type' => $this->type,
  14. 'cnpj' => $this->cnpj,
  15. 'responsible' => $this->responsible,
  16. 'email' => $this->email,
  17. 'phone' => $this->phone,
  18. 'category_id' => $this->category_id,
  19. 'category' => $this->whenLoaded('category', fn() => new CategoryResource($this->category)),
  20. 'address' => $this->address,
  21. 'neighborhood' => $this->neighborhood,
  22. 'city' => $this->whenLoaded('city', fn() => new CityResource($this->city)),
  23. 'logo' => $this->whenLoaded('logo', fn() => $this->logo?->path
  24. ? ['url' => Storage::disk('s3')->temporaryUrl($this->logo->path, now()->addHours(24))]
  25. : null),
  26. 'discount_percentage' => $this->discount_percentage,
  27. 'contract_end' => $this->contract_end?->format('Y-m-d'),
  28. 'status' => $this->status,
  29. 'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
  30. ];
  31. }
  32. }