Comments
Description
Comments adds polymorphic comments and tagged-user notifications to Enso models.
The package exposes a reusable Commentable trait, ships the comments CRUD API used by the backoffice, tracks authorship through Enso audit traits, and supports tagged users through a pivot relation and queued notifications.
Delete behavior is configurable, allowing applications to either cascade comment deletion or block deletion when related comments exist.
Installation
Install the package:
composer require laravel-enso/comments
Run the package migrations:
php artisan migrate
Optional publishes:
php artisan vendor:publish --tag=comments-config
php artisan vendor:publish --tag=comments-mail
php artisan vendor:publish --tag=comments-factory
Default configuration:
return [
'editableTimeLimit' => 24 * 60 * 60,
'onDelete' => 'cascade',
'humanReadableDates' => true,
'loggableMorph' => [
'commentable' => [],
],
];
Features
- Polymorphic one-to-one and one-to-many comments through the
Commentabletrait. - Tagged users stored on a pivot table and notified through queued notifications.
- Comments API with list, create, update, destroy, and user option endpoints.
- Configurable delete strategy via
restrictorcascade. - Automatic parent touching for updated commentable records.
Usage
Add the trait to any model that should expose comments:
use Illuminate\Database\Eloquent\Model;
use LaravelEnso\Comments\Traits\Commentable;
class Post extends Model
{
use Commentable;
}
Available relationships:
comment()comments()
When a model is deleted, the package will either reject the deletion or cascade comment deletion based on enso.comments.onDelete.
Tagged users can be synchronized and notified through the Comment model:
$comment->syncTags($taggedUsers)->notify('/posts/1');
API
HTTP routes
GET api/core/commentsPOST api/core/commentsPATCH api/core/comments/{comment}DELETE api/core/comments/{comment}GET api/core/comments/users
Route names:
core.comments.indexcore.comments.storecore.comments.updatecore.comments.destroycore.comments.users
Model surface
LaravelEnso\\Comments\\Models\\Comment
Useful methods:
scopeFor(array $params): BuildersyncTags(array $taggedUsers)notify(string $path)
Depends On
Required Enso packages:
laravel-enso/core↗laravel-enso/dynamic-methods↗laravel-enso/helpers↗laravel-enso/migrator↗laravel-enso/track-who↗laravel-enso/users↗
Companion frontend package:
Contributions
are welcome. Pull requests are great, but issues are good too.
Thank you to all the people who already contributed to Enso!