PHP code example of agilepixels / laravel-rateable

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

    

agilepixels / laravel-rateable example snippets


// Add a rating for a model
$model->createRating($rating = 4, $author = $user, $body = 'Very nice!');

// Calculate the average rating for a model
$model->averageRating();

// Sum the ratings for a model
$model->sumRating();



namespace App;

use Illuminate\Database\Eloquent\Model;
use AgilePixels\Rateable\Traits\HasRating;

class Product extends Model
{
    use HasRating;
}



namespace App;

use Illuminate\Database\Eloquent\Model;
use AgilePixels\Rateable\Traits\AddsRating;

class User extends Model
{
    use AddsRating;
}

$product->createRating($rating, $author)

$product->createRating($rating, $author, $body)

$rating->createComment($author, $body)

$product->averageRating();
$product->averageRatingAsPercentage();
$product->sumRating();

$product->average_rating
$product->average_rating_as_percentage
$product->sum_rating
bash
php artisan migrate
bash
php artisan vendor:publish --provider="AgilePixels\Rateable\RateableServiceProvider" --tag="config"