aabosham / laravel-comment
为您的出色 Laravel 项目提供另一个评论系统。
v1.0.1
2022-05-28 16:24 UTC
Requires
- php: ^7.1.3|^8.0
- illuminate/database: ^6.0|^7.0|^8.0|^9
Requires (Dev)
- fzaninotto/faker: ^1.8
- orchestra/testbench: ~3.5.0|~3.6.0|~3.7.0|~3.8.0|^4.0|^5.0|^6.0
- phpunit/phpunit: ^7.4
- scrutinizer/ocular: ^1.5
This package is auto-updated.
Last update: 2024-09-06 11:33:19 UTC
README
为您的出色 Laravel 项目提供另一个评论系统。
版本兼容性
对于 >5.5
您可以使用 ^1.0.0
版本。
安装
通过 Composer
$ composer require aaboshamravel-comment
如果您不使用自动发现,或者使用 Laravel 版本 < 5.5,请将服务提供者添加到您的 app.php 文件中
\Aabosham\LaravelComment\LaravelCommentServiceProvider::class
发布配置和迁移文件,然后迁移评论表。
$ php artisan vendor:publish $ php artisan migrate
将 CanComment
特性添加到您的 User 模型中。
use Aabosham\LaravelComment\CanComment; class User extends Model { use CanComment; // ... }
将 Commentable
接口和 HasComments
特性添加到您的可评论模型中。
use Aabosham\LaravelComment\Contracts\Commentable; use Aabosham\LaravelComment\HasComments; class Product extends Model implements Commentable { use HasComments; // ... }
如果您想使用自己的评论模型,创建一个新的并扩展我的评论模型。
use Aabosham\LaravelComment\Models\Comment as LaravelComment; class Comment extends LaravelComment { // ... }
别忘了更新 config/comment.php
文件中的模型名称。
评论包包含几种模式。
1- 如果您想让用户对可评论模型进行评分;
class Product extends Model implements Commentable { use HasComments; public function canBeRated(): bool { return true; // default false } //... }
2- 如果您想对可评论模型的评论进行审批;
class Product extends Model implements Commentable { use HasComments; public function mustBeApproved(): bool { return true; // default false } // ... }
3- 有时候您可能不想对所有用户的评论进行审批;
class User extends Model { use CanComment; protected $fillable = [ 'isAdmin', // .. ]; public function canCommentWithoutApprove(): bool { return $this->isAdmin; } // .. }
使用方法
$user = App\User::first(); $product = App\Product::first(); // $user->comment(Commentable $model, $comment = '', $rate = 0); $user->comment($product, 'Lorem ipsum ..', 3); // approve it -- if the user model `canCommentWithoutApprove()` or you don't use `mustBeApproved()`, it is not necessary $product->comments[0]->approve(); // get avg rating -- it calculates approved average rate. $product->averageRate(); // get total comments count -- it calculates approved comments count. $product->totalCommentsCount();
提示:您可能想查看 tests/CommentTest.php 文件以检查所有潜在的用法。
变更日志
请查看 CHANGELOG 了解最近更改的信息。
测试
$ composer test
贡献
请参阅 CONTRIBUTING 和 CONDUCT 以获取详细信息。
安全
如果您发现任何安全问题,请通过电子邮件 mehmet.aydin.bahadir@gmail.com 联系,而不是使用问题跟踪器。
致谢
许可证
MIT 许可证 (MIT)。请参阅 许可证文件 了解更多信息。