feat: many category and sub can be in playlist
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo; // ← Add this
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany; // ← Add this
|
||||
use App\Traits\HasComments; // Add this
|
||||
use App\Traits\HasLikes;
|
||||
@@ -14,7 +15,7 @@ class MusicPlaylist extends Model
|
||||
protected $table = 'music_playlists';
|
||||
|
||||
protected $fillable = [
|
||||
'category_id', 'subcategory_id','name', 'slug', 'description', 'image_id', 'order', 'is_active'
|
||||
'name', 'slug', 'description', 'image_id', 'order', 'is_active'
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
@@ -31,14 +32,14 @@ class MusicPlaylist extends Model
|
||||
'is_saved',
|
||||
'saved_count'
|
||||
];
|
||||
public function category(): BelongsTo
|
||||
public function categories(): BelongsToMany
|
||||
{
|
||||
return $this->belongsTo(MusicCategory::class, 'category_id');
|
||||
return $this->belongsToMany(MusicCategory::class, 'music_category_playlist', 'playlist_id', 'category_id');
|
||||
}
|
||||
|
||||
public function subcategory(): BelongsTo
|
||||
|
||||
public function subcategories(): BelongsToMany
|
||||
{
|
||||
return $this->belongsTo(MusicSubcategory::class, 'subcategory_id');
|
||||
return $this->belongsToMany(MusicSubcategory::class, 'music_subcategory_playlist', 'playlist_id', 'subcategory_id');
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user