beksos/reviewmaster

Laravel 生态系统中用于模型用户评论的包,例如电商系统中的产品评论。

安装: 10

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:laravel-package

v1.0.1 2021-09-13 16:17 UTC

This package is auto-updated.

Last update: 2024-09-14 18:04:25 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

此包是从 Jalal Uddinhttps://github.com/dgvai/laravel-user-review 上创建的原始包 Github 分支出来的,并进行了一些改进。

此包使用了一个特性,可以对模型进行用户评论(您可以指定用户模型),并提供星级/评分,管理员只能回复一次作为支持响应。(类似于 Google Play 商店评论系统)。此包可以与任何项目一起使用,如电子商务、商店、店铺等模型。

要求

  • PHP >= 7.1
  • Laravel >= 5.6

安装

使用 COMPOSER

composer require beksos/reviewmaster

配置

导出资源(迁移和配置)

php artisan vendor:publish --provider="Beksos\Review\ReviewerServiceProvider"

运行迁移

php artisan migrate

清除配置缓存

php artisan config:cache

用法

Reviewable 特性添加到您希望用户进行评论和评分的模型中。例如对于 产品模型,在 config/reviewmaster 文件中指定用户模型,默认使用 User。

<?php 
namespace App;

use Beksos\Review\Reviewable;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use Reviewable;
    ...
    ...
}

?>

为产品创建评论

描述

makeReview(object $user, int $rating [, string $review])

返回

评论对象的实例

示例

    $product = Product::find($id);
    $user = auth()->user();

    $product->makeReview($user,3,'Very good product!');

评论属性

    // Get all active reviews of the product
    $product->reviews();

    // Get neumetic review count (average)
    $product->rating;

    // Get percentage review count (average)
    $product->rating_percent;

    /**
    *   NOTE: THIS PERCENTAGE IS BASED ON 5 STAR RATING, IF YOU WANT CUSTOM STAR, USE BELLOW
    *   This is configured via the config file comes with this package: user-review.php
    *   You can also set environment variable for your systems default star count
    *
    *   (.env)  SYSTEM_RATING_STAR_COUNT=5 
    */

    $product->averageRating(10);    //percentage for 10 starrted model

    // Get rating given to the product by a user:
    $product->userRating($user);

    /**
     *  Get Filtered Review
     *  Like, get only reviews that has been given 4 stars!
     * 
    */

    $product->filter(4);

    /**
     * Get it's percentage, which can be shown in the progress bar!
     * */ 
    $product->filteredPercentage(4);      // ex: output: 75 


    /**
     *  PULLING OUT REVIEWS
     *  There are several ways you can
     *  pull out reviews of products
    */

    // Get all reviews of all products
    $reviews = Beksos\Review\Review::all();              // all reviews
    $reviews = Beksos\Review\Review::active()->get();    // all active reviews
    $reviews = Beksos\Review\Review::inactive()->get();  // all inactive reviews
    $reviews = Beksos\Review\Review::daily()->get();     // all daily reviews
    $reviews = Beksos\Review\Review::monthly()->get();   // all monthly reviews
    $reviews = Beksos\Review\Review::yearly()->get();    // all yearly reviews

    // You can also chain these methods
    $reviews = Beksos\Review\Review::monthly()->active()->get();  // get aa monthly active reviews

    // Get reviews of a product
    $product->reviews();


    /**
     *  $reviews has some attributes
     *  Let's assume we are taking the first review
    */
    $review = $reviews->first();

    /**
     *  This the model object of the traited model
     *  In our case it is product
     * 
    */

    $review->model;     //  so $review->model->name with return the $product->name
    $review->user;      //  return User model that reviewed the model

    // Get review text
    $review->review_text;

    // Get review reply
    $review->reply;

    // reply a review by admin:
    $review->reply('Thanks for being with us!');

    // making active/inactive
    $review->makeActive();
    $review->makeInactive();

目前就是这样!愿真主保佑,更新将很快带来新功能。