CommentTransformer.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace App\Repositories\Transformers\Course;
  3. use Carbon\Carbon;
  4. use League\Fractal\TransformerAbstract;
  5. use App\Repositories\Models\Course\Comment;
  6. /**
  7. * Class CourseCommentTransformer.
  8. *
  9. * @package namespace App\Repositories\Transformers;
  10. */
  11. class CommentTransformer extends TransformerAbstract
  12. {
  13. /**
  14. * Transform the CourseComment entity.
  15. *
  16. * @param \App\Repositories\Models\Course\Comment $model
  17. *
  18. * @return array
  19. */
  20. public function transform(Comment $model)
  21. {
  22. return [
  23. 'id' => (int)$model->id,
  24. 'content' => $model->content,
  25. 'course_id' => (int)$model->course_id,
  26. // 'course_name' => $model->course->title ?? '',
  27. 'user_id' => (int)$model->user_id,
  28. 'user' => $model->user()->get(['name', 'headimg']),
  29. 'course_video_id' => (int)$model->course_video_id,
  30. // 'course_video_name' =>$model->course_video->title,
  31. 'points' => (int)$model->points,
  32. 'created_at' => $model->created_at->diffForHumans(),
  33. // 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
  34. ];
  35. }
  36. }