40 lines
875 B
PHP
40 lines
875 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
class Music extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'user_id',
|
|
'title',
|
|
'artist',
|
|
'file_path',
|
|
'type', // public or private
|
|
'image_id',
|
|
];
|
|
|
|
// Relation to user (optional)
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
protected $appends = ['url', 'image_url'];
|
|
// Accessor for full URL
|
|
public function getUrlAttribute()
|
|
{
|
|
return asset('storage/' . $this->file_path);
|
|
}
|
|
public function image()
|
|
{
|
|
return $this->belongsTo(Image::class, 'image_id');
|
|
}
|
|
public function getImageUrlAttribute()
|
|
{
|
|
return $this->image ? asset('storage/' . $this->image->path) : null;
|
|
}
|
|
}
|