123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Repositories\Models\Course;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\Model;
- use App\Repositories\Models\Base\Resource;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- /**
- * Class Course.
- *
- * @package namespace App\Repositories\Models;
- */
- class Course extends Model implements Transformable
- {
- use TransformableTrait;
- protected $table = 'course_courses';
- protected $guarded = [];
- protected $casts = [
- 'settings' => 'json',
- 'labels' => 'json',
- ];
- public function category()
- {
- return $this->belongsTo(Category::class, 'category_id', 'id')->select(['name', 'id']);
- }
- public function thumb_resource()
- {
- return $this->belongsTo(Resource::class, 'thumb', 'id')->select(['path', 'id', 'url']);
- }
- public function attaches()
- {
- return $this->hasMany(Attach::class, 'course_id', 'id');
- }
- public function subscribe()
- {
- return $this->hasOne(Subscribe::class)->select(['id', 'is_watched', 'progress', 'watched_at', 'created_at']);
- }
- public function comments()
- {
- return $this->hasMany(Comment::class);
- }
- public function getVideoNumsAttribute()
- {
- return Video::query()->where('course_id', $this->attributes['id'])->where('status', ModelStatusEnum::OK)->count();
- }
- }
|