feat: user rating and comment
This commit is contained in:
+15
-1
@@ -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'];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user