---
title: "Locking threads — Comments for Laravel | Roundly"
description: "Lock a subject’s whole comment section, or the whole thread under one comment, to stop new and edited comments."
url: https://roundly-consulting.com/open-source/docs/comments-for-laravel/locking
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Comments for Laravel](https://roundly-consulting.com/open-source/docs/comments-for-laravel.md)

# Locking threads

Two lock levels cover resolved or heated discussions:

```php
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.

```php
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](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

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

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/comments-for-laravel.md)
