betalabs/laravel-comment 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

betalabs/laravel-comment

最新稳定版本:1.0.3

Composer 安装命令:

composer require betalabs/laravel-comment

包简介

Just another comment system for laravel projects.

README 文档

README

Latest Version on Packagist Software License Build Status Total Downloads

Just another comment system for laravel projects.

Version Compatibility

Laravel Laravel Comment
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.x 0.4.x
5.6.x 0.5.x
5.7.x 0.6.x

Install

Via Composer

$ composer require actuallymab/laravel-comment

Laravel 5.5 uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.

If you don't use auto-discovery, or using Laravel version < 5.5 Add service provider to your app.php file

\Actuallymab\LaravelComment\LaravelCommentServiceProvider::class

Publish & Migrate comments table.

$ php artisan vendor:publish
$ php artisan migrate

Add CanComment trait to your User model.

use Actuallymab\LaravelComment\CanComment;

Add Commentable trait to your commentable model(s).

use Actuallymab\LaravelComment\Commentable;

If you want to have your own Comment Model create a new one and extend my Comment model.

class Comment extends Actuallymab\LaravelComment\Comment
{
  ...
}

Comment package comes with several modes.

1- If you want to Users can rate your model(s) with comment set canBeRated to true in your Commentable model.

class Product extends Model {
  use Commentable;

  protected $canBeRated = true;

  ...
}

2- If you want to approve comments for your commentable models, you must set mustBeApproved to true in your Commentable model.

class Product extends Model {
  use Commentable;

  protected $mustBeApproved = true;

  ...
}

3- You don't want to approve comments for all users (think this as you really want to approve your own comments?). So add your User model an isAdmin method and return it true if user is admin.

class User extends Model {
  use CanComment;
  
  protected $fillable = [
    'isAdmin',
    ....
  ];

  public function isAdmin() {
    return $this->isAdmin;
  }

  ...
}

Usage

$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();

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email mehmet.aydin.bahadir@gmail.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 17.73k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 64
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-06-04