muba00/laravel-comment
为您的出色Laravel项目提供的另一个评论系统。
1.0.7
2020-09-26 16:55 UTC
Requires
- php: ^7.1.3
- illuminate/database: ~5.5.0|~5.6.0|~5.7.0|~5.8.0|^6.0|^7.0|^8.0
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
README
为您的出色Laravel项目提供的另一个评论系统。
版本兼容性
对于大于5.5的版本,您可以使用^1.0.0
版本。
安装
通过Composer
$ composer require muba00/laravel-comment
如果您不使用自动发现,或者使用Laravel版本小于5.5,请将服务提供者添加到您的app.php文件中
\Muba00\LaravelComment\LaravelCommentServiceProvider::class
发布配置和迁移,然后迁移评论表。
$ php artisan vendor:publish $ php artisan migrate
将CanComment
特质添加到您的User模型中。
use Muba00\LaravelComment\CanComment; class User extends Model { use CanComment; // ... }
将Commentable
接口和HasComments
特质添加到您的commentable模型中。
use Muba00\LaravelComment\Contracts\Commentable; use Muba00\LaravelComment\HasComments; class Product extends Model implements Commentable { use HasComments; // ... }
如果您想使用自己的Comment模型,创建一个新的并扩展我的Comment模型。
use Muba00\LaravelComment\Models\Comment as LaravelComment; class Comment extends LaravelComment { // ... }
别忘了在config/comment.php
文件中更新模型名称。
Comment包附带多种模式。
1- 如果您想用户可以对您的commentable模型进行评分;
class Product extends Model implements Commentable { use HasComments; public function canBeRated(): bool { return true; // default false } //... }
2- 如果您想对您的commentable模型的评论进行审批;
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)。请参阅许可证文件以获取更多信息。