1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?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 Course.
- *
- * @package namespace App\Repositories\Models;
- */
- class Course extends Model implements Transformable
- {
- use TransformableTrait;
- protected $table = 'course_courses';
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- // protected $fillable = [
- // 'category_id',
- // 'title',
- // 'type',
- // 'labels',
- // 'thumb',
- // 'short_description',
- // 'description',
- // 'published_at',
- // 'is_rec',
- // 'comment_status',
- // 'status',
- // ];
- protected $guarded = [];
- protected static function booted()
- {
- self::language();
- }
- public function category()
- {
- return $this->belongsTo(Category::class, 'category_id', 'id');
- }
- public function thumb_resource()
- {
- return $this->belongsTo(Resource::class, 'thumb', 'id')->select(['path', 'id', 'url']);
- }
- public function attaches()
- {
- return $this->hasMany(Attach::class, 'course_id', 'id');
- }
- public function subscribe()
- {
- return $this->hasOne(UserRecord::class);
- }
- public function comments()
- {
- return $this->hasMany(Comment::class);
- }
- public function getVideoNumsAttribute()
- {
- return Video::query()->where('course_id', $this->attributes['id'])->where('status', ModelStatusEnum::OK)->count();
- }
- }
|