Add likes to comments
This commit is contained in:
@@ -8,9 +8,16 @@ use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
|
||||
use Maize\Markable\Markable;
|
||||
use Maize\Markable\Models\Like;
|
||||
|
||||
class Comment extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
use HasFactory, SoftDeletes, Markable;
|
||||
|
||||
protected static $marks = [
|
||||
Like::class
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
@@ -58,4 +65,12 @@ class Comment extends Model
|
||||
? $this->parent->depth() + 1
|
||||
: 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get cached like count
|
||||
*/
|
||||
public function likeCount(): int
|
||||
{
|
||||
return cache()->remember('commentLikes' . $this->id, 300, fn() => $this->likes->count());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user