PHP code example of canylmz / laravel-rating

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

    

canylmz / laravel-rating example snippets


Canylmz\Rating\RatingServiceProvider::class,

use Canylmz\Rating\CanRate;
use Canylmz\Rating\Contracts\Rater;

class User extends Model implements Rater
{
    use CanRate;

    // ...
}

use Canylmz\Rating\CanBeRated;
use Canylmz\Rating\Contracts\Rateable;

class Post extends Model implements Rateable
{
    use CanBeRated;

    // ...
}

use Canylmz\Rating\Rate;
use Canylmz\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="Canylmz\Rating\RatingServiceProvider" --tag="config"
bash
php artisan vendor:publish --provider="Canylmz\Rating\RatingServiceProvider" --tag="migrations"
bash
php artisan migrate