Download the PHP package lenorix/laravel-comments without Composer
On this page you can find all versions of the php package lenorix/laravel-comments. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lenorix/laravel-comments
More information about lenorix/laravel-comments
Files in lenorix/laravel-comments
Package laravel-comments
Short Description Associate comments with Eloquent models
License Unlicense
Homepage https://github.com/lenorix/laravel-comments
Informations about the package laravel-comments
Laravel Comments
Associate comments with any Eloquent model. Comments can be nested (replies), reacted to with emoji, rendered from Markdown to sanitized HTML, held for moderation, mention other users, and notify people who subscribed to a model's comments.
Installation
Install the package via composer:
Publish and run the migrations:
Publish the config file:
Setup
Add the HasComments trait to any model that should receive comments, and implement
commentableName() / commentUrl() — notifications use them to describe where a
comment was posted:
If comments have an author (most apps do), prepare your user model and point the config at it:
If you want to allow comments from guests (no logged-in user), set:
Usage
Creating and reading comments
Replies
A Comment can itself receive comments, which makes it a reply:
Deleting a comment leaves its replies in place by default. Set
delete_replies_along_comments to true in the config to delete them too, at every
depth of nesting.
Reactions
Reacting always requires an identified commentator, even if allow_anonymous_comments
is true — react() throws AnonymousReactionsNotAllowed when no commentator can be
resolved. Guests can comment, but never react.
Only emoji listed in allowed_reactions are accepted — react() throws
DisallowedReaction otherwise. Set allowed_reactions to an empty array to allow any
reaction.
Markdown rendering and sanitizing
By default, original_text is rendered from Markdown into HTML and stored in text.
Any HTML tag or attribute not on the sanitizer's whitelist is stripped. Extend that
whitelist per tag in the config:
Use text to display a comment, and original_text when editing it.
Syntax highlighting for code blocks is not bundled. Add it by writing a
CommentTransformer that runs after MarkdownToHtmlTransformer in
comment_transformers and rewrites $comment->text with whichever highlighter your
app already depends on.
Moderation
Register who can approve pending comments, and expose the signed approve/reject routes:
Override shouldBeAutomaticallyApproved() on a custom Comment subclass for
fine-grained approval rules instead of the global config flag.
Notifications and subscriptions
All subscribers hear about every new approved comment on the model. Participating
subscribers only hear about it if they have commented on that model themselves. The
author of a comment is never notified about their own comment.
Customize the sender and the mail's content:
This publishes editable Blade templates to resources/views/vendor/comments/mail/.
The pending-comment mail includes working approve/reject buttons.
Mentions
Mentions are represented as <span data-mention="{id}">{name}</span> inside the
rendered text. Enable them and pick a raw-input convention (the default recognizes
@[Name](id)):
Mentioned commentators are notified once the comment is approved, not while pending.
Authorization
The package ships a CommentPolicy, automatically bound to your configured Comment
model. Extend it to customize create, update, delete, react, see, approve
and reject rules:
Events
CommentCreated and CommentDeleted are dispatched from the Comment model's own
created/deleted lifecycle, so they fire no matter how the row came to exist or
disappear — a top-level comment, a reply, direct model calls, or the
delete_replies_along_comments cascade all dispatch them:
CommentCreated fires even for a pending comment — check $event->comment->isApproved()
if you only care about visible ones.
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
- lenorix
- All Contributors
License
Released into the public domain under The Unlicense.
All versions of laravel-comments with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^11.0||^12.0||^13.0
league/commonmark Version ^2.4