59 lines
1.5 KiB
PHP
59 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo; // ← Add this
|
|
use Illuminate\Database\Eloquent\Relations\HasMany; // ← Add this
|
|
use App\Traits\HasComments; // Add this
|
|
class MusicPlaylist extends Model
|
|
{
|
|
use HasComments;
|
|
protected $table = 'music_playlists';
|
|
|
|
protected $fillable = [
|
|
'category_id', 'subcategory_id','name', 'slug', 'description', 'image_id', 'order', 'is_active'
|
|
];
|
|
|
|
protected $casts = [
|
|
'is_active' => 'boolean',
|
|
'order' => 'integer',
|
|
];
|
|
protected $appends = [
|
|
'comments_count',
|
|
'has_user_commented',
|
|
'user_comment',
|
|
'user_comment_id'
|
|
];
|
|
public function category(): BelongsTo
|
|
{
|
|
return $this->belongsTo(MusicCategory::class, 'category_id');
|
|
}
|
|
|
|
public function subcategory(): BelongsTo
|
|
{
|
|
return $this->belongsTo(MusicSubcategory::class, 'subcategory_id');
|
|
}
|
|
|
|
|
|
public function musics(): HasMany
|
|
{
|
|
return $this->hasMany(Music::class, 'playlist_id');
|
|
}
|
|
|
|
public function image(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Image::class);
|
|
}
|
|
|
|
public function getActiveMusicsAttribute()
|
|
{
|
|
return $this->musics()->where('is_active', true)->orderBy('order')->get();
|
|
}
|
|
|
|
public function getTotalDurationAttribute()
|
|
{
|
|
return $this->musics()->where('is_active', true)->sum('duration');
|
|
}
|
|
}
|