byrcsc/laravel-comments ยท 1.x
Configuration.
Every key in config/comments.php, its default, what it does, and what happens when it is wrong.
Publish the file before you migrate โ table names and actor key types are read by the migration when it runs:
php artisan vendor:publish --tag="comments-config"Key reference
| Key | Default | Purpose |
|---|---|---|
table_names | The four defaults below | Table names. Every key must be present |
actor_key_type | int | Key type of every polymorphic identity column |
max_depth | 3 | How deep replies may nest; null for unlimited |
max_length | null | Longest body in characters; null for no limit |
default_status | approved | Initial status for a model-authored comment |
guest_status | pending | Initial status for a guest comment |
allowed_reactions | Six emoji | Accepted reaction strings; null to accept any |
attachments.disk | null | Default disk for attachImage(); null uses the app default |
attachments.directory | comments/attachments | Default directory for attachImage(); '' is the disk root |
notifications.reply.enabled | false | Whether the shipped reply notification delivers |
notifications.reply.channels | ['mail'] | Channels it delivers over; may not be empty |
Environment variables
| Variable | Key |
|---|---|
COMMENTS_ACTOR_KEY_TYPE | actor_key_type |
COMMENTS_ATTACHMENTS_DISK | attachments.disk |
COMMENTS_NOTIFY_REPLIES | notifications.reply.enabled |
Table names
'table_names' => [
'comments' => 'comments',
'comment_reactions' => 'comment_reactions',
'comment_revisions' => 'comment_revisions',
'comment_attachments' => 'comment_attachments',
],The models read these values, so renaming in one place is all it takes. Set them before migrating; renaming a table that already holds comments requires your own migration.
Every key must be present. A missing or blank name fails at boot.
Actor key type
'actor_key_type' => env('COMMENTS_ACTOR_KEY_TYPE', 'int'),Covers the commentator on a comment, the reactor on a reaction, and the editor
on a revision. Valid values are int, uuid, ulid, and string.
The commentable model's key is independent โ adjust commentable_id in the
published migration directly when those models do not use integer keys. See
installation.
Limits
'max_depth' => 3,
'max_length' => null,Both are enforced when a comment is created, and max_length again on every
edit. Exceeding either throws rather than truncating. null disables the limit.
Tightening max_depth never reshapes existing threads. See
threads and replies.
Initial status
'default_status' => 'approved',
'guest_status' => 'pending',Valid values: pending, approved, rejected, spam. Guests are read from
their own key, so raising default_status never publishes anonymous content. A
commentable implementing DecidesCommentStatus beats both. See
initial status.
Allowed reactions
'allowed_reactions' => ['๐', '๐', 'โค๏ธ', '๐', '๐', '๐ข'],Reacting with anything outside the list throws. Set it to null to accept any
non-empty string up to 64 characters.
The key must be present even when set to null: absent is not the same as null,
so a published config predating the key announces that it needs updating rather
than quietly turning the allowlist off.
Reactions are stored and compared exactly as given. See reactions.
Attachments
'attachments' => [
'disk' => env('COMMENTS_ATTACHMENTS_DISK'),
'directory' => 'comments/attachments',
],Only attachImage() reads the directory. attach() records a file your
application already stored, so it is told the disk and path outright and falls
back to disk only for the name it writes down.
Only the shape is validated at boot. Whether the disk exists is the filesystem config's business โ failing a boot over it in an application that never attaches anything would be the wrong trade.
Notifications
'notifications' => [
'reply' => [
'enabled' => env('COMMENTS_NOTIFY_REPLIES', false),
'channels' => ['mail'],
],
],An empty channel list is a configuration error rather than another way to say off. See reply notifications.
Boot-time validation
Almost everything above is validated when the package boots, not on first use. A
blank table name, an unknown actor key type, a negative depth, a non-integer
length, an unknown status, a malformed allowlist, a non-string disk, or an empty
channel list all throw an InvalidConfigurationException during boot.
The exception names the key and what it received, so the fix is the config edit that caused it rather than a query error long afterwards.
Publish tags
| Tag | Writes |
|---|---|
comments-config | config/comments.php |
comments-migrations | The four table migrations |
comments-translations | lang/vendor/comments/en/comments.php |
comments-views | resources/views/vendor/comments/mail/reply.blade.php |