12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?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';
- /**
- * 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']);
- }
- }
|