x-laravel/commentable
Add polymorphic, threaded comments to any Laravel model with x-laravel/commentable. Just use the trait on posts, pages, or products to get nested replies, editing, soft deletes, and configurable moderation out of the box.
Contracts\CanComment + Concerns\Commenter for models that author comments.Contracts\HasComments + Concerns\Commentable for models that receive comments.connection, table, and comment model before running migrations or writing queries.Post, then let a User author them. Standardize whether your app calls the receiver-side helper (comment() / addComment()) or the author-side helper, depending on trait placement and method signatures.rootComments() for top-level comments and replies() for children. For user profile/history screens, use authoredComments() and isOn() checks.Basic commenting
HasComments/Commentable on the model being commented on, e.g. Post.CanComment/Commenter on the author model, e.g. User.Replies and threading
reply() / addReply() against an existing parent comment.rootComments() for thread roots and replies() for children. For deep threads, eager load replies to avoid N+1 queries, and consider pagination or a max display depth for very large threads.Listing and checks
authoredComments() for “my comments” screens.isOn() to check whether a comment belongs to a given model before showing actions or authorizing replies/deletes.Soft deletes and cleanup
model:prune for left-behind comments. The package schedules pruning with configurable frequency and chunk size; verify the scheduler in your app and tune chunk size for large comment tables.Events
Events\Commented, Events\Replied, and Events\CommentDeleted for notifications, audit logs, search indexing, or moderation queues.Customization
connection and table aligned with your migrations. If you use a non-default connection, verify polymorphic relations and foreign keys still behave as expected.ULIDs everywhere
Cross-model parent comments
Anonymous comments need app-level controls
authoredComments() will not represent anonymous comments as authored by a user.Soft-delete edge cases
Pruning can duplicate work
model:prune, avoid adding a second schedule entry unless you intentionally want a different cadence.Events after commit
RefreshDatabase/DatabaseTruncation carefully when asserting after-commit events. If you use Event::fake(), verify listeners still receive expected payloads.N+1 in deep threads
replies() nested to any depth can produce heavy query counts. Eager load constrained reply chains or load replies per level in the UI.Debugging checklist
config:clear.How can I help you explore Laravel packages today?