NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Comments for Laravel

Locking threads

Two lock levels cover resolved or heated discussions:

use RoundlyConsulting\Comments\Facades\Comments;

Comments::lock($post);              // block all new/edited comments on the post
Comments::unlock($post);
Comments::isLocked($post);          // bool
$post->commentsLocked();            // bool, same answer

Comments::lockThread($comment);     // no new replies anywhere below it, no edits in it
Comments::unlockThread($comment);
Comments::isThreadLocked($reply);   // bool — true when it or any ancestor is locked

$comment->lockReplies();            // same as Comments::lockThread($comment)
$comment->unlockReplies();          // same as Comments::unlockThread($comment)
$comment->isLocked();               // bool — this comment's own thread lock only
  • Subject lock — Comments::lock($post) stores a CommentLock row (one per subject; locking twice is a no-op). New comments, replies and edits on that subject throw CommentsLockedException until Comments::unlock().
  • Thread lock — Comments::lockThread($comment) sets locked_at on the comment. It covers the whole subtree: no new replies anywhere below it and no edits to it or any comment in it — a reply to a reply is still in the thread, and soft-deleting a comment inside a locked thread keeps everything below it locked.
  • Comments::isThreadLocked($reply) is true when the comment or any ancestor is locked; $comment->isLocked() reports only the comment’s own lock.
  • Locking fires CommentThreadLocked and unlocking CommentThreadUnlocked — only when the state actually changes.
use RoundlyConsulting\Comments\Exceptions\CommentsLockedException;

try {
    Comments::on($post)->as($user)->body('Late to the party')->post();
} catch (CommentsLockedException $e) {
    // "This thread is locked and cannot accept new or edited comments."
}

CommentResource exposes each comment’s own thread lock as locked, so clients can hide the reply box. With authorization on, locking and unlocking check the lock and unlock abilities — see Authorization.

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 crypto

By 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.