StudentResource.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Resources;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  6. use Illuminate\Http\Resources\Json\JsonResource;
  7. use Illuminate\Support\Facades\Storage;
  8. class StudentResource extends JsonResource
  9. {
  10. public function toArray(Request $request): array
  11. {
  12. return [
  13. 'id' => $this->id,
  14. 'unit_id' => $this->unit_id,
  15. 'name' => $this->name,
  16. 'birth_date' => $this->birth_date?->format('Y-m-d'),
  17. 'document_number' => $this->document_number,
  18. 'gender' => $this->gender,
  19. 'email' => $this->email,
  20. 'phone' => $this->phone,
  21. 'postal_code' => $this->postal_code,
  22. 'street' => $this->street,
  23. 'address_number' => $this->address_number,
  24. 'neighborhood' => $this->neighborhood,
  25. 'city_id' => $this->city_id,
  26. 'state_id' => $this->state_id,
  27. 'complement' => $this->complement,
  28. 'payer_name' => $this->payer_name,
  29. 'how_did_you_know_us' => $this->how_did_you_know_us,
  30. 'notes' => $this->notes,
  31. 'photo_url' => $this->photo_url ? Storage::url($this->photo_url) : null,
  32. 'status' => $this->status,
  33. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  34. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  35. ];
  36. }
  37. public static function collection($resource): AnonymousResourceCollection
  38. {
  39. return parent::collection($resource);
  40. }
  41. }