PHP code example of centrex / laravel-ratings

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

    

centrex / laravel-ratings example snippets


return [
    'users' => [
        'table' => 'users',
        'primary_key' => 'user_id',
    ],

    'max_rating' => 5,
    
    'undo_rating' => true,
];

use Centrex\Ratings\Concerns\InterectsWithRating;

class Product extends Model
{
    use InterectsWithRating;
    
    // ...
}

$product = Product::find(1);

$product->rate(4);

$product->rate(score: 2);

$product->ratings;

$product->ratingPercent(maxLength: 5);

$product->unrate();

$product->averageRating; // "4.0000"
$product->averageRatingByUser; // "5.0000"
$product->averageSumOfUser; // 5
$product->ratedByUsers; // 2
$product->ratedInTotal; // 2
$product->sumRating; // "8" 

public string $iconBgColor = 'text-yellow-300';
public string $iconFgColor = 'text-yellow-400';
public float $score = 0;
public string $size = 'text-base';
public bool $static = false;
bash
php artisan vendor:publish --tag="ratings-config"