StudentResource.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. class StudentResource extends JsonResource
  8. {
  9. public function toArray(Request $request): array
  10. {
  11. return [
  12. 'id' => $this->id,
  13. 'unit_id' => $this->unit_id,
  14. 'name' => $this->name,
  15. 'birth_date' => $this->birth_date?->format('Y-m-d'),
  16. 'document_number' => $this->document_number,
  17. 'gender' => $this->gender,
  18. 'email' => $this->email,
  19. 'phone' => $this->phone,
  20. 'postal_code' => $this->postal_code,
  21. 'street' => $this->street,
  22. 'address_number' => $this->address_number,
  23. 'neighborhood' => $this->neighborhood,
  24. 'city_id' => $this->city_id,
  25. 'state_id' => $this->state_id,
  26. 'complement' => $this->complement,
  27. 'payer_name' => $this->payer_name,
  28. 'how_did_you_know_us' => $this->how_did_you_know_us,
  29. 'notes' => $this->notes,
  30. 'status' => $this->status,
  31. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  32. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  33. ];
  34. }
  35. public static function collection($resource): AnonymousResourceCollection
  36. {
  37. return parent::collection($resource);
  38. }
  39. }