xentixar/filament-comments
Composer 安装命令:
composer require xentixar/filament-comments
包简介
A powerful recursive comments system for Filament, allowing you to add nested commenting functionality to your Filament resources and custom Livewire pages.
README 文档
README
A powerful recursive comments system for Filament, allowing you to add nested commenting functionality to your Filament resources and custom Livewire pages.
Overview
Filament Comments is a robust and feature-rich commenting system designed for both Filament admin panels and custom Livewire pages. It provides a seamless way to implement nested comments, discussions, and feedback mechanisms across your application.
Key Benefits
- Versatile Integration: Works seamlessly in both Filament admin panels and custom Livewire pages
- Real-time Updates: Powered by Livewire for instant comment updates without page refreshes
- Flexible Architecture: Support for multiple comment types and customizable configurations
- Activity Tracking: Monitor comment interactions and user engagement
- Modern UI: Clean and intuitive interface that matches Filament's design language
- Table Support: Built-in support for Filament tables in both admin and custom pages
- Smart Pagination: Elegant "Show More" and "Show Less" pagination for comments and replies
Features
- Easy integration with Filament admin panel
- Recursive (nested) comments support
- Real-time comments using Livewire
- Activity tracking for comments
- Configurable and customizable
- Supports multiple comment types
- Built-in migrations and configurations
- Rich text editor support
- Comment threading and replies
- Incremental pagination with "Show More" and "Show Less" controls
- User mention functionality with notifications
Requirements
- PHP 8.1+
- Laravel 10.0+
- Filament 3.0+
Installation
You can install the package via composer:
composer require xentixar/filament-comments
Publish the service provider:
php artisan vendor:publish --provider="Xentixar\FilamentComment\FilamentCommentServiceProvider"
Run the migrations:
php artisan migrate
Usage
Adding Comments to Your Models
To enable comments on your model, use the HasFilamentComment trait and implement Commentable contract:
use Xentixar\FilamentComment\Models\Traits\HasFilamentComment; use Xentixar\FilamentComment\Contracts\Commentable; class Post extends Model implements Commentable { use HasFilamentComment; protected $fillable = ['title', 'content', 'user_id']; }
Using in Filament Admin Panel
To add the comment preview functionality to your Filament resource tables:
use Xentixar\FilamentComment\Tables\Actions\PreviewCommentAction; class PostResource extends Resource { public static function table(Table $table): Table { return $table ->columns([ // Your columns... ]) ->actions([ Tables\Actions\ViewAction::make(), Tables\Actions\EditAction::make(), PreviewCommentAction::make() ]); } }
Using in Custom Livewire Pages
You can also use the comment system in your custom Livewire pages:
use Xentixar\FilamentComment\Tables\Actions\PreviewCommentAction; use Filament\Tables\Concerns\InteractsWithTable; use Filament\Tables\Contracts\HasTable; class CustomPage extends Component implements HasTable { use InteractsWithTable; public function table(Table $table): Table { return $table ->columns([ // Your columns... ]) ->actions([ PreviewCommentAction::make() ]); } }
User Mentions
The comment system supports user mentions with notifications. Users can be mentioned in comments using the @username syntax:
// In your comment
@john This is a great idea!
When a user is mentioned, they will receive a notification if notifications are enabled in the configuration.
Adding Username to User Model
To ensure proper display of usernames in comments, you need to make sure your User model has both name and username attributes. The name attribute is used for display purposes, while the username attribute is used for mentions.
- Add both
nameandusernameattributes to your User model if they don't exist:
// In your User model class User extends Authenticatable { protected $fillable = [ 'name', 'username', 'email', 'password', // other fields... ]; }
- If you're using different attribute names for the user's display name or username, you can customize this in the configuration:
// In config/filament-comments.php return [ 'user_model' => \App\Models\User::class, 'user_table' => 'users', 'mention_column' => 'username', // Change this to your custom username attribute 'display_name_column' => 'name', // Change this to your custom display name attribute // other configuration options... ];
- If you need to add migrations to add these fields to your users table:
php artisan make:migration add_name_and_username_to_users_table
Then in the migration file:
public function up() { Schema::table('users', function (Blueprint $table) { $table->string('name')->nullable()->after('id'); $table->string('username')->unique()->after('name'); }); } public function down() { Schema::table('users', function (Blueprint $table) { $table->dropColumn(['name', 'username']); }); }
Configuration
You can publish and customize the configuration file:
php artisan vendor:publish --provider="Xentixar\FilamentComment\FilamentCommentServiceProvider" --tag="config"
This will publish the configuration file to config/filament-comments.php. Here you can customize various aspects of the comments system:
return [ 'comment_table' => 'comments', 'comment_activity_table' => 'comment_activities', 'user_table' => 'users', 'user_model' => \App\Models\User::class, 'mention_column' => 'username', 'send_notifications' => true, 'mention_notification_title' => 'mentioned in a comment!', 'display_name_column' => 'name' ];
Configuration Options
- Comment Table: Customize the table name for storing comments
- Comment Activity Table: Customize the table name for storing comment activities
- User Model: Specify your application's user model
- User Table: Customize the table name for storing users
- Mention Column: Specify which attribute to use for user mentions
- Send Notifications: Enable or disable notifications for user mentions
- Mention Notification Title: Customize the title of mention notifications
- Display Name Column: Specify which attribute to use for displaying user and avatar
Contributing
Please see CONTRIBUTING.md for details.
License
The MIT License (MIT). Please see License File for more information.
Support
For support, please open an issue in the GitHub repository.
Credits
xentixar/filament-comments 适用场景与选型建议
xentixar/filament-comments 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 4, 最近一次更新时间为 2025 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「plugin」 「comments」 「laravel」 「filament」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 xentixar/filament-comments 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xentixar/filament-comments 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 xentixar/filament-comments 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Twig extension for Timber which outputs HTML comments before and after the `include` tag
Laravel comment system
Comments system for your Laravel application. Features: can be used to comment on any model, HTML filter customization (HTMLPurifier), API, comment rating, replies, events, auth rules ...
WordPress plugin to force comments to go through the more liberal post HTML filters, rather than the restrictive comment filters.
Add a simple Disqus comments thread to your page types
统计信息
- 总下载量: 21
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 19
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-31