StudentTransformer.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. namespace App\Repositories\Transformers\User;
  3. use App\Repositories\Enums\SexEnum;
  4. use Carbon\Carbon;
  5. use League\Fractal\TransformerAbstract;
  6. use App\Repositories\Models\User\Student;
  7. /**
  8. * Class StudentTransformer.
  9. *
  10. * @package namespace App\Repositories\Transformers\User;
  11. */
  12. class StudentTransformer extends TransformerAbstract
  13. {
  14. /**
  15. * Transform the Student entity.
  16. *
  17. * @param \App\Repositories\Models\User\Student $model
  18. *
  19. * @return array
  20. */
  21. public function transform(Student $model)
  22. {
  23. return [
  24. 'id' => (int)$model->id,
  25. 'turename' => $model->turename,
  26. 'faculty' => $model->faculty,
  27. 'class' => $model->class,
  28. 'headimg' => $model->headimg,
  29. 'period' => $model->period,
  30. 'sex' => $model->sex,
  31. 'sex_text' => SexEnum::getDescription($model->sex),
  32. 'account' => $model->account,
  33. 'mobile' => $model->mobile,
  34. 'created_at' => $model->created_at->format(Carbon::DEFAULT_TO_STRING_FORMAT),
  35. 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
  36. ];
  37. }
  38. }