PartnerAgreementListResource.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334
  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. 'cnpj' => $this->cnpj,
  14. 'responsible' => $this->responsible,
  15. 'email' => $this->email,
  16. 'phone' => $this->phone,
  17. 'category_id' => $this->category_id,
  18. 'category' => $this->whenLoaded('category', fn() => new CategoryResource($this->category)),
  19. 'address' => $this->address,
  20. 'neighborhood' => $this->neighborhood,
  21. 'city' => $this->whenLoaded('city', fn() => new CityResource($this->city)),
  22. 'logo' => $this->whenLoaded('logo', fn() => $this->logo?->path
  23. ? ['url' => Storage::disk('s3')->temporaryUrl($this->logo->path, now()->addHours(24))]
  24. : null),
  25. 'discount_percentage' => $this->discount_percentage,
  26. 'contract_end' => $this->contract_end?->format('Y-m-d'),
  27. 'status' => $this->status,
  28. 'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
  29. ];
  30. }
  31. }