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'];
}
+5 -1
View File
@@ -25,7 +25,11 @@ class Media extends Model
'average_rating',
'user_rating',
'ratings_count',
'comments_count'
'comments_count',
'has_user_commented', // Add this
'user_comment', // Add this
'user_comment_id', // Add this
'has_user_rated' // Add this
];
public function image()
{
+5 -1
View File
@@ -43,7 +43,11 @@ public function tags(): BelongsToMany
return $this->belongsToMany(Tag::class, 'music_tags');
}
protected $appends = ['url', 'image_url' , 'average_rating', 'user_rating', 'comments_count'];
protected $appends = ['url', 'image_url' , 'average_rating', 'user_rating', 'comments_count' , 'has_user_commented', // Add this
'user_comment', // Add this
'user_comment_id', // Add this
'has_user_rated' // Add this];
];
public function getUrlAttribute()
{