PHP code example of compubel / laravel-rating

1. Go to this page and download the library: Download compubel/laravel-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/ */

    

compubel / laravel-rating example snippets


Compubel\Rating\RatingServiceProvider::class,

use Compubel\Rating\CanRate;
use Compubel\Rating\Contracts\Rater;

class User extends Model implements Rater
{
    use CanRate;

    // ...
}

use Compubel\Rating\CanBeRated;
use Compubel\Rating\Contracts\Rateable;

class Post extends Model implements Rateable
{
    use CanBeRated;

    // ...
}

use Compubel\Rating\Rate;
use Compubel\Rating\Contracts\Rating;

class Member extends Model implements Rating
{
    use Rate;

    // ...
}

$user->rate($post, 10);
$post->averageRating(User::class); // 10.0, as float

$user->rate($post, 10, false);

$user->rate($post, 10);
$user->hasRated($post); // true

$user->rate($post, 10);
$post->averageRating(User::class); // 10.0, as float

$user->rate($post, 10);
$user->rate($post, 10);
$post->countRatings(User::class); // 2, as integer
bash
php artisan vendor:publish --provider="Compubel\Rating\RatingServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Compubel\Rating\RatingServiceProvider" --tag="migrations"
bash
php artisan migrate