actuallymab / laravel-comment
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项目提供的另一个评论系统。
版本兼容性
Laravel | Laravel评论 |
---|---|
5.0.x | 0.1.x |
5.1.x | 0.1.x |
5.2.x | 0.1.x |
5.3.x | 0.2.x |
5.4.x | 0.3.x |
对于 >5.5,您可以使用 ^1.0.0 版本。
安装
通过Composer
$ composer require actuallymab/laravel-comment
如果您不使用自动发现,或使用Laravel版本 < 5.5,请将服务提供者添加到您的app.php文件中
\Actuallymab\LaravelComment\LaravelCommentServiceProvider::class
发布配置和迁移,然后迁移评论表。
$ php artisan vendor:publish $ php artisan migrate
将CanComment
特质添加到您的User模型中。
use Actuallymab\LaravelComment\CanComment; class User extends Model { use CanComment; // ... }
将Commentable
接口和HasComments
特质添加到您的可评论模型中。
use Actuallymab\LaravelComment\Contracts\Commentable; use Actuallymab\LaravelComment\HasComments; class Product extends Model implements Commentable { use HasComments; // ... }
如果您想创建自己的评论模型,创建一个新的模型并扩展我的评论模型。
use Actuallymab\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)。请参阅许可文件以获取更多信息。