artsites / comments
Laravel 和 Nova 的评论功能。
1.0.0
2023-07-18 09:23 UTC
Requires
- php: >=8.0
README
安装
composer require artsites/comments
迁移
php artisan migrate
发布
php artisan vendor:publish --provider="ArtSites\Comments\ServiceProvider" --tag="config"
php artisan vendor:publish --provider="ArtSites\Comments\ServiceProvider" --tag="js"
可选发布
如果您想自定义视图,可以将视图发布到
/resources/views/vendor/comments
php artisan vendor:publish --provider="ArtSites\Comments\ServiceProvider" --tag="views"
此外,您可以将 nova 资源发布到
/app/Nova/Comment.php以添加新特性字段
php artisan vendor:publish --provider="ArtSites\Comments\ServiceProvider" --tag="nova-resource"
警告 不要忘记替换命名空间
配置
路径
/config/comments.php
show_more_count- 点击“显示更多”按钮时的评论数
环境变量
此包使用 Google reCAPTCHA V3
请将生成的密钥添加到您的环境变量中
RECAPTCHA_SITE_KEY RECAPTCHA_SECRET_KEY
用法
在应该有评论的
model中添加 trait
use ArtSites\Comments\Models\Traits\HasComments; class SomeModel extends Model { use HasComments; ... }
在返回视图的
controller中添加一个$comments变量
$model = Model::first(); return view('***', [ ... 'model' => $model, 'comments' => $model->getComments(), ]);
要添加模板到视图,您需要添加
@include('comments::layout', ['comments' => $comments, 'model' => $model])
最后的点缀,向 Nova 的
resource添加HasMany关联
use Laravel\Nova\Fields\HasMany; HasMany::make('Comments', 'comments', \ArtSites\Comments\Nova\Comment::class),