AssociateValidationResource.php 1.1 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 AssociateValidationResource extends JsonResource
  7. {
  8. public function toArray(Request $request): array
  9. {
  10. return [
  11. 'id' => $this->id,
  12. 'name' => $this->name,
  13. 'cpf' => $this->cpf,
  14. 'registration' => $this->registration,
  15. 'photo_url' => $this->photo_path
  16. ? Storage::disk('s3')->temporaryUrl($this->photo_path, now()->addHours(24))
  17. : null,
  18. 'expiry_date' => $this->expiry_date?->format('d/m/Y'),
  19. 'dependents' => $this->dependents->map(function ($dependent) {
  20. return [
  21. 'id' => $dependent->id,
  22. 'name' => $dependent->name,
  23. 'kinship' => $dependent->kinship,
  24. 'status' => $dependent->status,
  25. 'expiry_date' => $this->expiry_date?->format('d/m/Y'),
  26. ];
  27. })->values(),
  28. ];
  29. }
  30. }