Attach.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Repositories\Models\Course;
  3. use App\Repositories\Enums\ModelStatusEnum;
  4. use App\Repositories\Models\Model;
  5. use App\Repositories\Models\Base\Resource;
  6. use Prettus\Repository\Contracts\Transformable;
  7. use Prettus\Repository\Traits\TransformableTrait;
  8. /**
  9. * Class CourseAttach.
  10. *
  11. * @package namespace App\Repositories\Models;
  12. */
  13. class Attach extends Model implements Transformable
  14. {
  15. use TransformableTrait;
  16. protected $table = 'course_attaches';
  17. /**
  18. * The attributes that are mass assignable.
  19. *
  20. * @var array
  21. */
  22. protected $guarded = [];
  23. public function course_video()
  24. {
  25. return $this->belongsTo(Video::class, 'course_video_id', 'id');
  26. }
  27. public function path_resource()
  28. {
  29. return $this->belongsTo(Resource::class, 'path', 'id')->select(['path', 'id', 'url']);
  30. }
  31. /**
  32. * 获取附件
  33. * @param $video_id
  34. * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
  35. */
  36. public static function byVideoIdGetLists($video_id)
  37. {
  38. return self::query()->where('course_video_id', $video_id)->with(['path_resource'])->where('status', ModelStatusEnum::OK)->get(['name', 'id', 'path', 'download_times']);
  39. }
  40. }