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

Spam & blocklist filter

Configure banned words or regexes and decide how a match is handled:

// config/comments.php
'blocklist' => ['spam', '/casino|viagra/i'],
'blocklist_action' => 'reject', // 'reject' | 'pending' | 'hidden'
  • Plain strings match case-insensitively as whole words — spam matches “Spam!” but not “spammer”.
  • Delimited entries such as /casino|viagra/i are used as regular expressions, as written.
  • A blank or non-string entry throws an InvalidConfigurationException naming comments.blocklist.

Actions

ActionA matching new comment is…A matching edit…
rejectNot stored — CommentRejectedException is thrown.Is refused — CommentRejectedException is thrown.
pendingStored with the pending status, awaiting review.Moves an approved comment to pending; a hidden one stays hidden.
hiddenStored with the hidden status.Moves the comment to hidden.

Edits run the same filter, so a comment posted clean cannot be edited into spam and stay public. An edit only ever tightens the status — it never lifts a hidden comment to pending, and a clean edit leaves a held comment for a moderator to approve.

use RoundlyConsulting\Comments\Exceptions\CommentRejectedException;

try {
    Comments::on($post)->as($user)->body($body)->post();
} catch (CommentRejectedException $e) {
    // $e->getMessage(): "This comment contains content that is not allowed."
}

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.