centrex / livewire-comments
Manege comments with livewire in laravel
v2.0.0
2025-10-29 06:31 UTC
Requires
- php: ^8.2|^8.3|^8.4
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- livewire/livewire: ^3.0|^4.0
Requires (Dev)
- larastan/larastan: ^2.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^8.5
- orchestra/testbench: ^9.5
- pestphp/pest: ^3.4
- pestphp/pest-plugin-arch: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- rector/rector: ^1.2
- spatie/laravel-ray: ^1.26
- dev-main
- v2.0.0
- v1.1.0
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-dependabot/github_actions/dependabot/fetch-metadata-3.0.0
- dev-dependabot/github_actions/ramsey/composer-install-4
- dev-dependabot/github_actions/actions/checkout-6
- dev-dependabot/github_actions/stefanzweifel/git-auto-commit-action-7
This package is auto-updated.
Last update: 2026-04-11 08:04:05 UTC
README
Real-time polymorphic comment threads built with Livewire. Supports nested replies, likes (by authenticated user or by IP/user-agent for guests), Markdown rendering, @mention linking, and soft-deletes.
Installation
composer require centrex/livewire-comments
php artisan vendor:publish --tag="livewire-comments-migrations"
php artisan migrate
Usage
1. Add the Livewire component to any Blade view
<livewire:comments :model="$post" />
The $model can be any Eloquent model — comments are stored polymorphically.
2. Add the HasUserAvatar trait to your User model (optional)
use Centrex\LivewireComments\Traits\HasUserAvatar; class User extends Authenticatable { use HasUserAvatar; // Provides avatar() → Gravatar URL based on email }
3. Comment model
use Centrex\LivewireComments\Models\Comment; // All top-level comments for a model Comment::parent()->where('commentable_type', Post::class) ->where('commentable_id', $post->id) ->with('children', 'user') ->get(); // Nested replies $comment->children; // ordered oldest-first $comment->isParent(); // true if no parent_id // Likes $comment->likes_count; $comment->isLiked(); $comment->removeLike();
4. Comment presenter
$comment->presenter()->markdownBody(); // HtmlString (Markdown rendered) $comment->presenter()->relativeCreatedAt(); // "2 hours ago" $comment->presenter()->replaceUserMentions($text); // links @mentions to user profiles
Config
php artisan vendor:publish --tag="livewire-comments-config"
// config/commentify.php 'users_route_prefix' => 'users', // used for @mention links: /users/{username}
Testing
composer test # full suite composer test:unit # pest only composer test:types # phpstan composer lint # pint
Changelog
Please see CHANGELOG for more information on what has changed recently.
Credits
License
The MIT License (MIT). Please see License File for more information.