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, or transferring comments onto a locked subject. |
InvalidCommentParentException | A reply’s parent belongs to another subject. |
InvalidCommentMetaPathException | whereMeta() or whereMetaMissing() gets a path that is not lowercase dot notation. |
InvalidCommentTransferException | Comments::transfer() targets the subject the comments already belong to. |
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 files, shipped in English (en) and Slovak (sk) with identical keys. Publish them to lang/vendor/comments to reword the keys, or add a folder per locale next to en and sk for another language:
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.',
'invalid_meta_path' => 'The comment meta path [:path] is invalid. Use dot-separated segments of lowercase letters, digits and underscores, none of them digits only.',
'transfer_same_subject' => 'Comments cannot be transferred to the subject they already belong to.',
];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.