StudentResponsibleResource.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Resources;
  3. use Carbon\Carbon;
  4. use Illuminate\Http\Request;
  5. use Illuminate\Http\Resources\Json\JsonResource;
  6. use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
  7. use App\Models\StudentResponsible;
  8. class StudentResponsibleResource extends JsonResource
  9. {
  10. /**
  11. * Transform the resource into an array.
  12. *
  13. * @return array<string, mixed>
  14. */
  15. public function toArray(Request $request): array
  16. {
  17. return [
  18. 'id' => $this->id,
  19. 'student_id' => $this->student_id,
  20. 'name' => $this->name,
  21. 'birth_date' => $this->birth_date?->format('Y-m-d'),
  22. 'cpf' => $this->cpf,
  23. 'gender' => $this->gender,
  24. 'degree' => $this->degree,
  25. 'email' => $this->email,
  26. 'phone' => $this->phone,
  27. 'street' => $this->street,
  28. 'address_number' => $this->address_number,
  29. 'postal_code' => $this->postal_code,
  30. 'neighborhood' => $this->neighborhood,
  31. 'city_id' => $this->city_id,
  32. 'state_id' => $this->state_id,
  33. 'complement' => $this->complement,
  34. 'notes' => $this->notes,
  35. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  36. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  37. ];
  38. }
  39. /**
  40. * @param \Illuminate\Database\Eloquent\Collection<StudentResponsible> $resource
  41. * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<StudentResponsibleResource>
  42. */
  43. public static function collection($resource): AnonymousResourceCollection
  44. {
  45. return parent::collection($resource);
  46. }
  47. }