1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Repositories\Models\Course;
- use App\Repositories\Models\Model;
- use App\Repositories\Models\Base\Resource;
- use App\Repositories\Models\UserVideoWatchRecord;
- use Prettus\Repository\Contracts\Transformable;
- use Prettus\Repository\Traits\TransformableTrait;
- /**
- * Class CourseVideo.
- *
- * @package namespace App\Repositories\Models;
- */
- class Video extends Model implements Transformable
- {
- use TransformableTrait;
- protected $table = 'course_videos';
- protected static function booted()
- {
- self::language();
- }
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- // protected $fillable = [];
- protected $guarded = [];
- public function getDurationTextAttribute()
- {
- return sec2time($this->attributes['duration']);
- }
- public function comments()
- {
- return $this->hasMany(Comment::class, 'course_video_id');
- }
- public function attaches()
- {
- return $this->hasMany(Attach::class, 'course_video_id');
- }
- public function course_chapter()
- {
- return $this->belongsTo(Chapter::class);
- }
- public function course()
- {
- return $this->belongsTo(Course::class);
- }
- public function getProgressAttribute()
- {
- return UserVideoWatchRecord::query()->where('video_id', $this->attributes['id'])->where('user_id', login_user_id())->value('progress') ?? 0;
- }
- public function url_resource()
- {
- return $this->belongsTo(Resource::class, 'url', 'id')->select(['path', 'id', 'url']);
- }
- public function subtitle_zh_path_resource()
- {
- return $this->belongsTo(Resource::class, 'subtitle_zh_path', 'id')->select(['path', 'id', 'url']);
- }
- public function subtitle_en_path_resource()
- {
- return $this->belongsTo(Resource::class, 'subtitle_en_path', 'id')->select(['path', 'id', 'url']);
- }
- }
|