orkhanahmadov / laravel-commentable
Laravel 评论模型
1.1.0
2021-06-07 09:17 UTC
Requires
- php: ^7.2|^8.0
- illuminate/database: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0
- phpunit/phpunit: ^8.0|^9.0
This package is auto-updated.
Last update: 2024-09-07 17:23:02 UTC
README
此包提供将评论添加到您现有的 Eloquent 模型中的功能。
要求
- PHP 7.2 或更高版本
- Laravel 6 或更高版本
安装
您可以通过 composer 安装此包
composer require orkhanahmadov/laravel-commentable
发布迁移和配置文件
php artisan vendor:publish --provider="Orkhanahmadov\LaravelCommentable\LaravelCommentableServiceProvider"
配置
配置文件包含以下设置
table_name
- 在此处您设置迁移的表名。默认为 "comments"。
用法
在您的任何现有 Eloquent 模型中使用 Orkhanahmadov\LaravelCommentable\Commentable
特性使其可评论。
use Illuminate\Database\Eloquent\Model; use Orkhanahmadov\LaravelCommentable\Commentable; class Post extends Model { use Commentable; }
要向模型添加评论,请从模型实例调用 comment()
方法。
$post = Post::find(1); $post->comment('Great post, thanks for sharing!');
要作为用户添加评论,请从模型实例调用 commentAs()
方法。
$post = Post::find(1); $user = User::find(5); $post->commentAs($user, 'Great post, thanks for sharing!');
每个评论还会保存请求的 IP 地址和 User-Agent。
测试
composer test
变更日志
请参阅 CHANGELOG 以获取有关最近更改的更多信息。
贡献
请参阅 CONTRIBUTING 以获取详细信息。
安全
如果您发现任何与安全相关的问题,请通过电子邮件 ahmadov90@gmail.com 联系,而不是使用问题跟踪器。
鸣谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 以获取更多信息。