feat: add imag_id to music
This commit is contained in:
+10
-1
@@ -14,6 +14,7 @@ class Music extends Model
|
||||
'artist',
|
||||
'file_path',
|
||||
'type', // public or private
|
||||
'image_id',
|
||||
];
|
||||
|
||||
// Relation to user (optional)
|
||||
@@ -21,10 +22,18 @@ 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user