Each lifecycle step dispatches an event under RoundlyConsulting\Comments\Events, carrying the comment on its $comment property (CommentMentioned carries $mention):
| Event | Payload | When |
|---|---|---|
CommentCreated | $comment | A comment row is created — any write, including factories. |
CommentUpdated | $comment | A body is edited through Comments::update(). |
CommentDeleted | $comment | A comment is soft-deleted (single or deleteAll()). |
CommentApproved | $comment | A comment is approved (single or approveAll()). |
CommentHidden | $comment | A comment is hidden — by a moderator, hideAll() or the auto-hide listener. |
CommentThreadLocked | $comment | lockThread() or lockReplies() actually locks the thread under the comment. |
CommentThreadUnlocked | $comment | unlockThread() or unlockReplies() actually lifts the lock. |
CommentMentioned | $mention | An approved comment mentions a resolved person it has not notified yet — on write, edit or approval; once per person. |
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Notification;
use RoundlyConsulting\Comments\Events\CommentCreated;
Event::listen(function (CommentCreated $event): void {
// $event->comment is the freshly created Comment
Notification::send(
$event->comment->commentable,
new NewCommentNotification($event->comment),
);
});The events use SerializesModels, so queued listeners work out of the box. Restoring a comment dispatches no event. Like and report events come from Likes for Laravel and Reports for Laravel.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.