betalabs / laravel-comment
为laravel项目提供的另一个评论系统。
1.0.3
2019-03-05 11:27 UTC
Requires
- php: ^7.1.3
- illuminate/database: ~5.5.0|~5.6.0|~5.7.0|~5.8.0
Requires (Dev)
- fzaninotto/faker: ^1.8
- orchestra/testbench: ~3.5.0|~3.6.0|~3.7.0|~3.8.0
- phpunit/phpunit: ^7.4
- scrutinizer/ocular: ^1.5
README
为laravel项目提供的另一个评论系统。
版本兼容性
安装
通过Composer
$ composer require actuallymab/laravel-comment
Laravel 5.5使用包自动发现,因此不需要您手动添加ServiceProvider。
如果您不使用自动发现或使用Laravel版本< 5.5,请将ServiceProvider添加到您的app.php文件中
\Actuallymab\LaravelComment\LaravelCommentServiceProvider::class
发布并迁移评论表。
$ php artisan vendor:publish $ php artisan migrate
将CanComment
特性添加到您的User模型中。
use Actuallymab\LaravelComment\CanComment;
将Commentable
特性添加到您的可评论模型中。
use Actuallymab\LaravelComment\Commentable;
如果您想使用自己的Comment模型,创建一个新的模型并扩展我的Comment模型。
class Comment extends Actuallymab\LaravelComment\Comment { ... }
Comment包包含几种模式。
1- 如果您想让用户可以对您的模型(s)进行评分,请在您的Commentable
模型中将canBeRated
设置为true。
class Product extends Model { use Commentable; protected $canBeRated = true; ... }
2- 如果您想批准您的可评论模型的评论,必须在您的Commentable
模型中将mustBeApproved
设置为true。
class Product extends Model { use Commentable; protected $mustBeApproved = true; ... }
3- 您不想对所有用户的评论进行批准(比如,您只想批准自己的评论?)。那么,请给您的User
模型添加一个isAdmin
方法,如果用户是管理员则返回true。
class User extends Model { use CanComment; protected $fillable = [ 'isAdmin', .... ]; public function isAdmin() { return $this->isAdmin; } ... }
用法
$user = App\User::find(1); $product = App\Product::find(1); // $user->comment(Commentable $model, $comment = '', $rate = 0); $user->comment($product, 'Lorem ipsum ..', 3); // approve it -- if you are admin or you don't use mustBeApproved option, it is not necessary $product->comments[0]->approve(); // get avg rating -- it calculates approved average rate. $product->averageRate(); // get total comment count -- it calculates approved comments count. $product->totalCommentCount();
变更日志
有关最近变更的更多信息,请参阅CHANGELOG。
测试
$ composer test
贡献
有关详细信息,请参阅CONTRIBUTING和CONDUCT。
安全性
如果您发现任何与安全性相关的问题,请通过电子邮件mehmet.aydin.bahadir@gmail.com联系,而不是使用问题跟踪器。
鸣谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。