feat: user rating and comment

This commit is contained in:
2026-05-20 15:52:28 +03:30
parent 02448db346
commit d0d48866f0
7 changed files with 171 additions and 19 deletions
+15 -1
View File
@@ -12,7 +12,7 @@ class Comment extends Model
'commentable_type',
'content',
];
protected $with = ['user'];
public function user()
{
return $this->belongsTo(User::class);
@@ -34,4 +34,18 @@ public function music()
{
return $this->belongsTo(Music::class, 'commentable_id')->where('commentable_type', Music::class);
}
// Check if comment belongs to current user
public function getIsOwnerAttribute()
{
return auth()->check() && $this->user_id === auth()->id();
}
// Add timestamps formatted
public function getFormattedCreatedAtAttribute()
{
return $this->created_at->diffForHumans();
}
protected $appends = ['is_owner', 'formatted_created_at'];
}