'boolean', ]; protected $appends = [ 'ott_title', 'has_translations', ]; protected $translation_buffer = null; protected $translations_buffer = null; public function __construct() { $this->translation_buffer = $this->translation; $this->translations_buffer = $this->translations; } public function items() { return $this->hasManyThrough(Video::class, SectionItem::class, 'section_id', 'id', 'id', 'video_id'); } public function categories() { return $this->hasManyThrough(Category::class, SectionCategory::class, 'section_id', 'id', 'id', 'category_id'); } public function translation() { $locale = 'en'; if (session()->has('frontend_locale')) { $locale = session()->get('frontend_locale'); } return $this->hasOne(SectionTranslation::class, 'section_id', 'id')->where('code', $locale); } public function translations() { return $this->hasMany(SectionTranslation::class, 'section_id', 'id'); } public function getOttTitleAttribute() { if ($this->translation_buffer) { return $this->translation_buffer->title; } return $this->title; } public function getHasTranslationsAttribute() { return $this->translations_buffer->count() > 0; } public function scopeActive($query) { return $query->where('active', true); } }