StudentContractResource.php 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 Illuminate\Support\Facades\Storage;
  8. use App\Models\StudentContract;
  9. class StudentContractResource extends JsonResource
  10. {
  11. public function toArray(Request $request): array
  12. {
  13. return [
  14. 'id' => $this->id,
  15. 'protocol' => $this->protocol,
  16. 'student_id' => $this->student_id,
  17. 'unit_id' => $this->unit_id,
  18. 'class_package_unit_id' => $this->class_package_unit_id,
  19. 'signature_date' => $this->signature_date ? Carbon::parse($this->signature_date)->format('d/m/Y') : null,
  20. 'end_date' => $this->end_date ? Carbon::parse($this->end_date)->format('d/m/Y') : null,
  21. 'class_quantity' => $this->class_quantity,
  22. 'weekday' => $this->weekday,
  23. 'start_time' => $this->start_time,
  24. 'end_time' => $this->end_time,
  25. 'second_weekday' => $this->second_weekday,
  26. 'second_start_time' => $this->second_start_time,
  27. 'second_end_time' => $this->second_end_time,
  28. 'due_day' => $this->recurring_day,
  29. 'tax_register' => $this->tax_register,
  30. 'installments' => $this->installments,
  31. 'enrollment_due_date' => $this->enrollment_due_date
  32. ? Carbon::parse($this->enrollment_due_date)->format('d/m/Y')
  33. : null,
  34. 'package_value' => $this->package_value,
  35. 'package_installments' => $this->package_installments,
  36. 'package_due_date' => $this->package_due_date
  37. ? Carbon::parse($this->package_due_date)->format('d/m/Y')
  38. : null,
  39. 'early_payment_discount' => $this->early_payment_discount,
  40. 'interest_rate' => $this->interest_rate,
  41. 'payment_method' => $this->payment_method,
  42. 'fine_cancelled' => $this->fine_cancelled,
  43. 'status' => $this->status,
  44. 'package_name' => $this->whenLoaded('classPackageUnit', fn () => $this->classPackageUnit?->name),
  45. 'unit_name' => $this->whenLoaded('unit', fn () => $this->unit?->fantasy_name),
  46. 'student_name' => $this->whenLoaded('student', fn () => $this->student->name),
  47. 'student_document' => $this->whenLoaded('student', fn () => $this->student->document_number),
  48. 'student_birth_date' => $this->whenLoaded('student', fn () => $this->student->birth_date?->format('d/m/Y')),
  49. 'student_phone' => $this->whenLoaded('student', fn () => $this->student->phone),
  50. 'student_city' => $this->whenLoaded('student', fn () => $this->student->city?->name),
  51. 'student_state_code' => $this->whenLoaded('student', fn () => $this->student->state?->code),
  52. 'file_url' => $this->file_url ? Storage::url($this->file_url) : null,
  53. 'file_type' => $this->file_type,
  54. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  55. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  56. ];
  57. }
  58. /**
  59. * @param \Illuminate\Database\Eloquent\Collection<StudentContract> $resource
  60. * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<StudentContractResource>
  61. */
  62. public static function collection($resource): AnonymousResourceCollection
  63. {
  64. return parent::collection($resource);
  65. }
  66. }