Exceptions & messages
All exceptions extend the abstract RoundlyConsulting\Comments\Exceptions\CommentsException, itself a RuntimeException:
| Exception | Thrown when |
|---|---|
InvalidCommentBodyException | The body is empty after trimming, or longer than max_length. |
MaxReplyDepthExceededException | A reply would be nested deeper than max_depth. |
CommentRejectedException | The body matches the blocklist with the reject action. |
CommentsLockedException | Writing or editing against a locked subject or inside a locked thread. |
InvalidCommentParentException | A reply’s parent belongs to another subject. |
UnauthorizedCommentActionException | The Gate denies an ability while authorization is on. |
A misconfigured setting is the one failure outside this hierarchy: it throws RoundlyConsulting\PackageToolkit\Exceptions\InvalidConfigurationException from the package toolkit, naming the key — see Configuration.
Translating messages
Exception messages come from the package’s language file. Publish it to lang/vendor/comments, then translate or override the keys — add a folder per locale next to en:
php artisan vendor:publish --tag="comments-translations"// lang/vendor/comments/en/comments.php
return [
'body_empty' => 'A comment body cannot be empty.',
'body_too_long' => 'A comment body cannot be longer than :max characters.',
'max_depth_exceeded' => 'A reply cannot be nested deeper than :max levels.',
'rejected' => 'This comment contains content that is not allowed.',
'locked' => 'This thread is locked and cannot accept new or edited comments.',
'foreign_parent' => 'A reply must be posted on the same subject as the comment it replies to.',
'unauthorized' => 'You are not authorized to perform this comment action.',
];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.