PHP code example of beksos / reviewmaster

1. Go to this page and download the library: Download beksos/reviewmaster library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

beksos / reviewmaster example snippets


 
namespace App;

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

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


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