UserTransformer.php 1.2 KB

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