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'];
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user