CommentTransformer.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Repositories\Transformers\Course;
  3. use League\Fractal\TransformerAbstract;
  4. use App\Repositories\Models\Course\Comment;
  5. /**
  6. * Class CourseCommentTransformer.
  7. *
  8. * @package namespace App\Repositories\Transformers;
  9. */
  10. class CommentTransformer extends TransformerAbstract
  11. {
  12. /**
  13. * Transform the CourseComment entity.
  14. *
  15. * @param \App\Repositories\Models\Course\Comment $model
  16. *
  17. * @return array
  18. */
  19. public function transform(Comment $model)
  20. {
  21. if (isApiModule()) {
  22. return $this->apiTransform($model);
  23. }
  24. return [
  25. 'id' => (int)$model->id,
  26. 'content' => $model->content,
  27. 'course' => $model->course,
  28. 'user' => $model->user,
  29. 'course_video' => (int)$model->course_video,
  30. 'updated_at' => $model->updated_at->format('Y-m-d H:i:s'),
  31. ];
  32. }
  33. public function apiTransform(Comment $model)
  34. {
  35. return [
  36. 'id' => (int)$model->id,
  37. 'content' => $model->content,
  38. // 'course' => $model->course,
  39. 'user' => $model->user,
  40. 'course_video' => (int)$model->course_video,
  41. 'updated_at' => $model->updated_at->diffForHumans(),
  42. ];
  43. }
  44. }