StudentContractResource.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_date' => $this->due_date ? Carbon::parse($this->due_date)->format('d/m/Y') : null,
  29. 'recurring_day' => $this->recurring_day,
  30. 'tax_register' => $this->tax_register,
  31. 'down_payment' => $this->down_payment,
  32. 'installments' => $this->installments,
  33. 'early_payment_discount' => $this->early_payment_discount,
  34. 'material_value' => $this->material_value,
  35. 'material_installments' => $this->material_installments,
  36. 'interest_rate' => $this->interest_rate,
  37. 'payment_method' => $this->payment_method,
  38. 'fine_cancelled' => $this->fine_cancelled,
  39. 'status' => $this->status,
  40. 'file_url' => $this->file_url ? Storage::url($this->file_url) : null,
  41. 'file_type' => $this->file_type,
  42. 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
  43. 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
  44. ];
  45. }
  46. /**
  47. * @param \Illuminate\Database\Eloquent\Collection<StudentContract> $resource
  48. * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<StudentContractResource>
  49. */
  50. public static function collection($resource): AnonymousResourceCollection
  51. {
  52. return parent::collection($resource);
  53. }
  54. }