123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?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 CourseAttach.
- *
- * @package namespace App\Repositories\Models;
- */
- class Attach extends Model implements Transformable
- {
- use TransformableTrait;
- protected $table = 'course_attaches';
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $guarded = [];
- public function course_video()
- {
- return $this->belongsTo(Video::class, 'course_video_id', 'id');
- }
- public function path_resource()
- {
- return $this->belongsTo(Resource::class, 'path', 'id')->select(['path', 'id', 'url']);
- }
- /**
- * 获取附件
- * @param $video_id
- * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
- */
- public static function byVideoIdGetLists($video_id)
- {
- return self::query()->where('course_video_id', $video_id)->with(['path_resource'])->where('status', ModelStatusEnum::OK)->get(['name', 'id', 'path', 'download_times']);
- }
- }
|