ufutx/laravel-comment
为laravel项目提供的另一个评论系统。
v1.1.4
2017-05-13 12:54 UTC
Requires
- php: >=5.6.4
- illuminate/database: 5.*
Requires (Dev)
- fzaninotto/faker: ~1.4
- mockery/mockery: ~0.9.0
- orchestra/database: 3.4.x@dev
- orchestra/testbench: ~3.4
- phpunit/phpunit: 5.*
README
**为laravel项目提供的另一个评论系统。
版本兼容性
安装
通过Composer
$ composer require ufutx/laravel-comment
将服务提供者添加到app.php文件
\Ufutx\LaravelComment\LaravelCommentServiceProvider::class
发布并迁移评论表。
$ php artisan vendor:publish $ php artisan migrate
将CanComment
特质添加到您的User模型。
use Ufutx\LaravelComment\CanComment;
将Commentable
特质添加到您的可评论模型。
use Ufutx\LaravelComment\Commentable;
如果您想有自己的评论模型,创建一个新的并扩展我的评论模型。
class Comment extends Ufutx\LaravelComment\Comment { ... }
评论包包含几种模式。
1- 如果您想让用户可以通过评论对您的模型进行评分,请在您的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, $pic = null); $user->comment($product, 'Lorem ipsum ..', 3, 'http://images.ufutx.com/201702/09/49fe31fdf2d4f74709f2cb00e1a9c49a.jpeg@1e_1c_2o_1l_200h_200w_90q.src'); // approve it -- if you are admin or you don't use mustBeApproved option, it is not necessary $product->comments[0]->approve(); //comment user model record $product->comments[0]->user // 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或zglore而不是使用问题跟踪器来报告。
致谢
许可证
MIT许可证(MIT)。有关更多信息,请参阅许可证文件。