1. Go to this page and download the library: Download ghanem/rating 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/ */
ghanem / rating example snippets
use Ghanem\Rating\Traits\Ratingable;
class Post extends Model
{
use Ratingable;
}
use Ghanem\Rating\Traits\CanRate;
class User extends Model
{
use CanRate;
}
// From the ratable model
$rating = $post->rating(['rating' => 5], $user);
// From the author model
$rating = $user->rate($post, ['rating' => 5]);
$rating = $post->ratingUnique(['rating' => 5], $user);
// Or from the author
$rating = $user->rateUnique($post, ['rating' => 5]);
$post->avgRating() // average rating
$post->sumRating() // sum of all ratings
$post->countRatings() // total count
$post->countPositive() // count where rating > 0
$post->countNegative() // count where rating < 0
$post->ratingPercent() // percentage (default max: 5)
$post->ratingPercent(10) // percentage with custom max
$post->weightedAvgRating() // weighted average