feat: add music feature

This commit is contained in:
2026-05-19 08:22:10 +03:30
parent b63fdc5439
commit 65db1bd5da
11 changed files with 489 additions and 10 deletions
+19 -8
View File
@@ -5,23 +5,34 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Music extends Model
{
{
use HasFactory;
protected $table = 'music';
protected $fillable = [
'user_id',
'title',
'artist',
'file_path',
'type', // public or private
'image_id',
'user_id', 'title', 'artist', 'file_path', 'type',
'playlist_id', 'image_id', 'duration', 'order', 'is_active'
];
protected $casts = [
'duration' => 'string',
'order' => 'integer',
'is_active' => 'boolean',
];
// Relation to user (optional)
public function user()
{
return $this->belongsTo(User::class);
}
public function playlist(): BelongsTo
{
return $this->belongsTo(MusicPlaylist::class, 'playlist_id');
}
public function tags(): BelongsToMany
{
return $this->belongsToMany(Tag::class, 'music_tag');
}
protected $appends = ['url', 'image_url'];
// Accessor for full URL
public function getUrlAttribute()
+34
View File
@@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class MusicCategory extends Model
{
protected $table = 'music_categories';
protected $fillable = [
'name', 'slug', 'description', 'image_id', 'order', 'is_active'
];
protected $casts = [
'is_active' => 'boolean',
'order' => 'integer',
];
public function playlists(): HasMany
{
return $this->hasMany(MusicPlaylist::class, 'category_id');
}
public function image(): BelongsTo
{
return $this->belongsTo(Image::class);
}
public function getActivePlaylistsAttribute()
{
return $this->playlists()->where('is_active', true)->get();
}
}
+44
View File
@@ -0,0 +1,44 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class MusicPlaylist extends Model
{
protected $table = 'music_playlists';
protected $fillable = [
'category_id', 'name', 'slug', 'description', 'image_id', 'order', 'is_active'
];
protected $casts = [
'is_active' => 'boolean',
'order' => 'integer',
];
public function category(): BelongsTo
{
return $this->belongsTo(MusicCategory::class, 'category_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');
}
}