imanborumand / laravel-comments
这是一个Laravel的包,可以用于启动具有连接多个模型能力的评论功能
dev-main
2023-01-04 06:54 UTC
Requires (Dev)
- orchestra/testbench: ^7.17
This package is auto-updated.
Last update: 2024-09-04 10:12:14 UTC
README
Laravel的评论包
使用此包,您可以轻松地为您的模型启用评论功能。
安装
通过Composer安装
composer require imanborumand/laravel-comments
现在运行以下命令发布迁移
php artisan migrate
还可以使用以下命令发布配置文件
php artisan vendor:publish --tag="laravel-comment"
用法
要使用,只需在您的模型中使用特质Imanborumand\LaravelComments\Traits\HasComment
。
use Imanborumand\LaravelComments\Traits\HasComment;
class Article extends Model
{
use HasComment;
}
$article = Article::first();
$article->storeComment('this is the first article!');
此包默认使用已认证的用户。当然,如果您愿意,您可以按照以下方式将喜欢的用户保存为评论发送者。
$article->storeComment('Hello, world!', user: User::first());
您还可以按照以下方式添加子评论
$article->storeComment('Hello, world!', parent: Comment::find(10));