All packages
Comments for Laravel
The Comments facade
Comments — RoundlyConsulting\Comments\Facades\Comments — is the whole API in one place. Writes start from a fluent builder that reads like a sentence; reads start from a query:
use RoundlyConsulting\Comments\Facades\Comments;
// Write — a fluent builder, or a typed DTO
$comment = Comments::on($post)->as($user)->body('Nice write-up!')->post();
Comments::write($writeCommentData);
// Edit and moderate
Comments::update($comment, 'Edited body');
Comments::delete($comment);
Comments::restore($comment);
Comments::approve($comment);
Comments::hide($comment);
// Read — site-wide, per subject or per author
Comments::query()->pending()->mostReported()->paginate();
Comments::for($post)->visible()->rootsOnly()->withReplies()->get();
Comments::byAuthor($user)->get();
// Lock a subject, or the thread under one comment
Comments::lock($post); Comments::unlock($post); Comments::isLocked($post);
Comments::lockThread($comment); Comments::unlockThread($comment); Comments::isThreadLocked($reply);| Comments::… | Returns | Does |
|---|---|---|
on($subject) | CommentBuilder | Start a comment: as(), body(), visible(), reply(), post(). |
write(WriteCommentData $data) | Comment | Write from a typed DTO. |
update($comment, $body) | Comment | Edit the body. |
delete($comment) / restore($comment) | void / Comment | Soft-delete and restore. |
approve($comment) / hide($comment) | Comment | Moderate. |
query() | CommentQuery | Site-wide read and moderation query — every subject. |
for($subject) / byAuthor($author) | CommentQuery | The same query, scoped to a subject or an author. |
lock($subject) / unlock($subject) / isLocked($subject) | CommentLock / void / bool | Lock a whole subject. |
lockThread($comment) / unlockThread($comment) / isThreadLocked($comment) | Comment / Comment / bool | Lock the thread under a comment. |
fake() | CommentsFake | Record every mutation in tests — see Testing. |
Builders
- Comments::on($subject) returns a CommentBuilder — as(), body(), visible(), reply(), then post(). The subject is a scope: a reply to another subject’s comment throws InvalidCommentParentException.
- Comments::query(), for($subject) and byAuthor($author) return a CommentQuery — filters, ordering, get() / paginate() / count() and the bulk approveAll() / hideAll() / deleteAll(). Build it through the facade or the manager: its bulk terminals run through the manager.
Model shorthands
$user->writeComment() and $comment->lockReplies() / unlockReplies() are sugar over the same manager, so behaviour, events and Comments::fake() are identical whichever form you use.
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.