ChapterTransformer.php 1.1 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\Chapter;
  6. /**
  7. * Class CourseChapterTransformer.
  8. *
  9. * @package namespace App\Repositories\Transformers;
  10. */
  11. class ChapterTransformer extends TransformerAbstract
  12. {
  13. /**
  14. * Transform the CourseChapter entity.
  15. *
  16. * @param \App\Repositories\Models\Course\Chapter $model
  17. *
  18. * @return array
  19. */
  20. public function transform(Chapter $model)
  21. {
  22. return [
  23. 'id' => (int)$model->id,
  24. 'title' => $model->title,
  25. 'course_id' => (int)$model->course_id,
  26. 'course_name' => $model->course ? $model->course->title : '',
  27. 'sort' => (int)$model->sort,
  28. 'status' => (int)$model->status,
  29. /* place your other model properties here */
  30. 'created_at' => $model->created_at->format(Carbon::DEFAULT_TO_STRING_FORMAT),
  31. 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
  32. ];
  33. }
  34. }