webudvikleren/laravel-commentable
最新稳定版本:v1.0.3
Composer 安装命令:
composer require webudvikleren/laravel-commentable
包简介
Easily add comments to any Laravel model
README 文档
README
Laravel Commentable adds a simple way to allow comments on any Eloquent model. It's modern, lightweight, and compatible with Laravel 10 and 11.
Features
- Add comments to any Eloquent model
- Polymorphic relationship
- User tracking (via
user_id) - Publishable migration and config
- Clean and extensible architecture
- Compatible with Laravel 10 & 11
Installation
composer require webudvikleren/laravel-commentable
Publish the migration (optional)
php artisan vendor:publish --tag=commentable-config php artisan migrate
If you don’t publish the migration, Laravel will auto-load it from the package.
Usage
Step 1: Add the trait to your model
use Webudvikleren\Commentable\Traits\Commentable; class Post extends Model { use Commentable; }
Step 2: Add comments
$post = Post::find(1); $post->comments()->create([ 'body' => 'This is a comment.', 'user_id' => auth()->id(), ]);
Step 3: Access comments
foreach ($post->comments as $comment) { echo $comment->body; }
Comment Model
By default, comments are stored in the comments table and use the provided Webudvikleren\Commentable\Models\Comment model.
You can override this in your app if needed by extending the model and binding it in a service provider.
Configuration
You can publish the config file to override defaults:
php artisan vendor:publish --tag=commentable-config
Example config/commentable.php (coming soon).
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
统计信息
- 总下载量: 108
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-06-20