feat: add many playlist for music
This commit is contained in:
@@ -43,9 +43,11 @@ public function subcategories(): BelongsToMany
|
||||
}
|
||||
|
||||
|
||||
public function musics(): HasMany
|
||||
public function musics(): BelongsToMany
|
||||
{
|
||||
return $this->hasMany(Music::class, 'playlist_id');
|
||||
return $this->belongsToMany(Music::class, 'music_playlist', 'playlist_id', 'music_id')
|
||||
->withPivot('order')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function image(): BelongsTo
|
||||
@@ -55,11 +57,11 @@ public function image(): BelongsTo
|
||||
|
||||
public function getActiveMusicsAttribute()
|
||||
{
|
||||
return $this->musics()->where('is_active', true)->orderBy('order')->get();
|
||||
return $this->musics()->where('music.is_active', true)->orderBy('music_playlist.order')->get();
|
||||
}
|
||||
|
||||
|
||||
public function getTotalDurationAttribute()
|
||||
{
|
||||
return $this->musics()->where('is_active', true)->sum('duration');
|
||||
return $this->musics()->where('music.is_active', true)->sum('music.duration');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user