Course.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 Course.
  10. *
  11. * @package namespace App\Repositories\Models;
  12. */
  13. class Course extends Model implements Transformable
  14. {
  15. use TransformableTrait;
  16. protected $table = 'course_courses';
  17. /**
  18. * The attributes that are mass assignable.
  19. *
  20. * @var array
  21. */
  22. // protected $fillable = [
  23. // 'category_id',
  24. // 'title',
  25. // 'type',
  26. // 'labels',
  27. // 'thumb',
  28. // 'short_description',
  29. // 'description',
  30. // 'published_at',
  31. // 'is_rec',
  32. // 'comment_status',
  33. // 'status',
  34. // ];
  35. protected $guarded = [];
  36. protected static function booted()
  37. {
  38. self::language();
  39. }
  40. public function category()
  41. {
  42. return $this->belongsTo(Category::class, 'category_id', 'id');
  43. }
  44. public function thumb_resource()
  45. {
  46. return $this->belongsTo(Resource::class, 'thumb', 'id')->select(['path', 'id', 'url']);
  47. }
  48. public function attaches()
  49. {
  50. return $this->hasMany(Attach::class, 'course_id', 'id');
  51. }
  52. public function subscribe()
  53. {
  54. return $this->hasOne(UserRecord::class);
  55. }
  56. public function comments()
  57. {
  58. return $this->hasMany(Comment::class);
  59. }
  60. public function getVideoNumsAttribute()
  61. {
  62. return Video::query()->where('course_id', $this->attributes['id'])->where('status', ModelStatusEnum::OK)->count();
  63. }
  64. }