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

Editing, deleting & restoring

use RoundlyConsulting\Comments\Facades\Comments;

Comments::update($comment, 'Edited body'); // dispatches CommentUpdated
Comments::delete($comment);                // soft delete, dispatches CommentDeleted
Comments::restore($comment);               // restore a soft-deleted comment

Comments::update() re-runs the write rules on the new body: it is trimmed and length-checked, blocked by a subject lock or a locked thread (CommentsLockedException), and run through the blocklist exactly like a write — a match is rejected with the reject action, or moves the comment to pending or hidden. Mentions are re-synced after every edit, and CommentUpdated is dispatched.

Soft deletes

Comments are soft-deleted, so nothing is lost by accident. Comments::delete() dispatches CommentDeleted; Comments::restore() brings the comment back and dispatches no event. Trashed comments stay reachable through Eloquent’s soft-delete scopes:

use RoundlyConsulting\Comments\Models\Comment;

Comment::onlyTrashed()->get();     // soft-deleted comments
Comment::withTrashed()->find($id); // include soft-deleted rows

The action behind update()

Comments::update() runs UpdateCommentAction, which takes an UpdateCommentData DTO — call it directly from a job (see DI and actions):

use RoundlyConsulting\Comments\Actions\UpdateCommentAction;
use RoundlyConsulting\Comments\DataTransferObjects\UpdateCommentData;

app(UpdateCommentAction::class)->execute(new UpdateCommentData(
    comment: $comment,
    body: 'Edited body',
));

With authorization enabled, edits check the update ability, deletes the delete ability and restores the restore ability.

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.