centrex/livewire-comments
最新稳定版本:v2.0.1
Composer 安装命令:
composer require centrex/livewire-comments
包简介
Manage comments with livewire in laravel
README 文档
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.
统计信息
- 总下载量: 2.47k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-11-13