laravel-enso/comments
Laravel Enso Comments adds a ready-to-use, polymorphic commenting layer to Enso applications. Attach comments to any Eloquent model, manage them through the included Vue interface, and give users a simple way to discuss records directly inside your admin panel.
laravel-enso/comments is not a standalone package — it is a module of the Enso ecosystem. Before installing, verify the host application already runs laravel-enso/enso (or at least Enso core, users, and the API conventions). If the app is a plain Laravel project, either install Enso scaffolding first or budget time to adapt the package's routes, controllers, and policies by hand.composer require laravel-enso/comments
php artisan vendor:publish --tag=comments
php artisan migrate
Inspect the published migration before running it on an existing database — the comments table name may collide with an in-house table.src/Comment.php — the Eloquent model and its relations (user, commentable, tagged users).src/Traits/Commentable.php (or similarly named trait) — the polymorphic comments() relation you add to any model.src/Policies/CommentPolicy.php — the authorization rules that govern create/update/delete.src/routes/api.php — the HTTP surface (index, store, update, destroy), and any tagging endpoints.config/enso/comments.php (or the package config) — notification and tagging toggles.use LaravelEnso\Comments\Traits\Commentable;
class Project extends Model
{
use Commentable;
}
POST /api/comments with body, commentable_type, commentable_id), then list it back with GET /api/comments?commentable_type=...&commentable_id=.... Confirm the comment appears with its author and that a second user cannot edit it — that proves the policy layer is active.Trait-per-model, not a central registry. Enso's comments are polymorphic, so the normal pattern is to add the trait to each model that should be discussable (orders, projects, tickets). The relation is then $project->comments, usually eager-loaded with ->with('user') to avoid N+1s in listings.
Authorization belongs in the policy, not the controller. The package's selling point is "policy enforced rules," which typically means: any authenticated user with access to the parent record can comment; authors can edit their own comments; admins or record owners can delete. Enso registers the policy automatically in most setups, but if comments are created through a custom controller, call $this->authorize('create', Comment::class) explicitly. For per-record rules (e.g. "only the project owner can comment on a locked project"), extend the policy with a createFor/custom ability and check the parent model.
User tagging. Tagging is normally expressed either as an array of user IDs in the payload or as @username tokens in the body, which the package resolves server-side. When integrating with a frontend, keep tagging and notification logic on the server: send IDs or mention tokens, and let the package dispatch notifications. If you implement a custom tag parser, reuse the package's resolution path so mentioned users still receive the real-time notification.
Real-time notifications depend on Laravel broadcasting, not just the package. The working combination is:
BROADCAST_DRIVER set to pusher, redis, or log for local testing,php artisan queue:work) because notifications are queued,App.Models.User.{id}),Without those four pieces the comments still save, but the "real time" part silently does nothing.
Integration tips.
@enso-ui/comments counterpart version-matched; mismatches show up as missing props or 404s on endpoints.user and any tagged-user relation, and paginate — long threads on a busy record will otherwise become a slow endpoint.created, deleted) for audit logging or analytics rather than overriding the controller.Comment model and rebind it in a service provider, or override the notification class; avoid editing vendor files because Composer updates will overwrite them.composer why-not before committing to the package, and plan a fork or replacement if the app is on a modern Laravel.log driver means notifications are "sent" but never seen. Test with log first, then switch to a real driver. Watch storage/logs/laravel.log and the failed-jobs table.Relation::morphMap(), the commentable_type stored in the database changes from a fully qualified class to your alias. The frontend and any hard-coded type checks must use the same alias, or comments silently attach to "nothing" and return empty threads.deleting listener on the commentable model to purge comments, or use a database foreign key with cascadeOnDelete — but only if you control the migration.CommentPolicy is registered in AuthServiceProvider (or that Enso's auto-registration is enabled for the namespace) and test with Gate::forUser($user)->allows('update', $comment).php artisan config:clear locally and config:cache in deployment; stale cached config is a common cause of notifications not firing.api/comments may already exist in the application. Run php artisan route:list --path=comments after install to see what actually won and which middleware applies.SHOW TABLES LIKE 'comments'), confirm the trait is on the model (class_uses_recursive), confirm the policy via Gate, confirm the queue worker is running, then confirm the frontend subscribes to the right private channel. That sequence isolates most failures in this package.Comment model and its notifications (custom payloads), and model events (side effects like audit logs). These three cover most day-to-day customization without forking the package.How can I help you explore Laravel packages today?