StudentResponsibleResource.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. 'company' => $this->company,
  26. 'profession' => $this->profession,
  27. 'email' => $this->email,
  28. 'phone' => $this->phone,
  29. 'street' => $this->street,
  30. 'address_number' => $this->address_number,
  31. 'postal_code' => $this->postal_code,
  32. 'neighborhood' => $this->neighborhood,
  33. 'city_id' => $this->city_id,
  34. 'state_id' => $this->state_id,
  35. 'complement' => $this->complement,
  36. 'notes' => $this->notes,
  37. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  38. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  39. ];
  40. }
  41. /**
  42. * @param \Illuminate\Database\Eloquent\Collection<StudentResponsible> $resource
  43. * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<StudentResponsibleResource>
  44. */
  45. public static function collection($resource): AnonymousResourceCollection
  46. {
  47. return parent::collection($resource);
  48. }
  49. }