'boolean', 'order' => 'integer', ]; protected $appends = [ 'comments_count', 'has_user_commented', 'user_comment', 'user_comment_id', 'is_liked', 'likes_count', 'is_saved', 'saved_count' ]; public function categories(): BelongsToMany { return $this->belongsToMany(MusicCategory::class, 'music_category_playlist', 'playlist_id', 'category_id'); } public function subcategories(): BelongsToMany { return $this->belongsToMany(MusicSubcategory::class, 'music_subcategory_playlist', 'playlist_id', 'subcategory_id'); } public function musics(): BelongsToMany { return $this->belongsToMany(Music::class, 'music_playlist', 'playlist_id', 'music_id') ->withPivot('order') ->withTimestamps(); } public function image(): BelongsTo { return $this->belongsTo(Image::class); } // Image shown on the detail (show-by-id) screen; image() is the list thumbnail. public function detailImage(): BelongsTo { return $this->belongsTo(Image::class, 'detail_image_id'); } public function getActiveMusicsAttribute() { return $this->musics()->where('music.is_active', true)->orderBy('music_playlist.order')->get(); } public function getTotalDurationAttribute() { return $this->musics()->where('music.is_active', true)->sum('music.duration'); } }