Add likes to comments

This commit is contained in:
2026-01-10 19:41:23 +01:00
parent 41c34e6d89
commit b133db0573
3 changed files with 74 additions and 2 deletions

View File

@@ -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());
}
}