centrex/livewire-comments

Manege comments with livewire in laravel

Maintainers

Package info

github.com/centrex/livewire-comments

pkg:composer/centrex/livewire-comments

Statistics

Installs: 2 464

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 4

v2.0.0 2025-10-29 06:31 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.