1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- <?php
- namespace App\Repositories\Transformers\Course;
- use App\Repositories\Enums\CourseCommentStatusEnum;
- use App\Repositories\Enums\CourseRecEnum;
- use App\Repositories\Enums\CourseTypeEnum;
- use App\Repositories\Enums\ModelStatusEnum;
- use Carbon\Carbon;
- use League\Fractal\TransformerAbstract;
- use App\Repositories\Models\Course\Course;
- /**
- * Class CourseTransformer.
- *
- * @package namespace App\Repositories\Transformers;
- */
- class CourseTransformer extends TransformerAbstract
- {
- /**
- * Transform the Course entity.
- *
- * @param \App\Repositories\Models\Course\Course $model
- *
- * @return array
- */
- public function transform(Course $model)
- {
- return [
- 'id' => (int)$model->id,
- 'title' => $model->title,
- 'category_id' => $model->category_id,
- 'category_name' => optional($model->category)->name,
- 'type' => $model->type,
- 'type_text' => CourseTypeEnum::getDescription($model->type),
- 'labels' => str2arr($model->labels),
- 'slug' => $model->slug,
- 'thumb' => $model->thumb,
- 'thumb_resource' => $model->thumb_resource,
- 'short_description' => $model->short_description,
- 'description' => $model->description,
- 'published_at' => $model->published_at,
- 'is_rec' => $model->is_rec,
- 'is_rec_text' => CourseRecEnum::getDescription($model->is_rec),
- 'user_count' => $model->user_count,
- 'comment_status' => $model->comment_status,
- 'comment_status_text' => CourseCommentStatusEnum::getDescription($model->comment_status),
- 'sort' => $model->sort,
- 'status' => $model->status,
- 'watch_progress' => $model->subscribe ? $model->subscribe->progress : false,
- 'status_test' => ModelStatusEnum::getDescription($model->status),
- 'created_at' => $model->created_at->format(Carbon::DEFAULT_TO_STRING_FORMAT),
- 'updated_at' => $model->updated_at->format(Carbon::DEFAULT_TO_STRING_FORMAT)
- ];
- }
- }
|