Easily setup rating system in your laravel poject
composer require code4mk/lara-rating
php artisan vendor:publish --provider="Code4mk\LaraRate\LaraRateServiceProvider" --tag=config
php artisan vendor:publish --provider="Code4mk\LaraRate\LaraRateServiceProvider" --tag=migrations
config/laraRate.php
"rater_table_name" => "users",
"rater_retrive_columns" =>["id","email"]
php artisan config:clear
int $productID, int $raterID, int $rate, string $comment
use Krate;
Krate::create($productID,$userID,$rate,$comment)
int $productID, int $raterID, int $rate, string $comment
use Krate;
Krate::update($productID,$raterID,$rate,$comment);
- get specific product's rating details
int productID
Krate::getRatings($productID);
- output
~ Krate::getRatings(3)
[
{
"id": 1,
"product_id": 3,
"rater_id": 3,
"rating": 5,
"comment": "5star",
"created_at": "2019-05-10 16:25:10",
"updated_at": "2019-05-10 16:25:10",
"rater": {
"id": 3,
"email": "maruf@gmail.com"
}
},
{
"id": 2,
"product_id": 3,
"rater_id": 2,
"rating": 2,
"comment": "2star",
"created_at": "2019-05-10 16:26:58",
"updated_at": "2019-05-10 16:26:58",
"rater": {
"id": 2,
"email": "jamal@gmail.com"
}
}
]
- rating type
int productID
Krate::getRatingStat($productID);
- output
~ Krate::getRatingStat(3)
{
"rateType": {
"one_star": {
"star": 0,
"percent": 0
},
"two_star": {
"star": 1,
"percent": 50
},
"three_star": {
"star": 0,
"percent": 0
},
"four_star": {
"star": 0,
"percent": 0
},
"five_star": {
"star": 1,
"percent": 50
}
},
"total_rater": 2,
"rating": 4
}
- customer/rater/user's rating lists
int raterID
Krate::getRaterRatings($raterID);
~ Krate::getRaterRatings(2)
[
{
"id": 1,
"product_id": 1,
"rater_id": 1,
"rating": 5,
"comment": "5 star",
"created_at": "2019-05-11 00:55:46",
"updated_at": "2019-05-11 00:55:46",
"product": {
"name": "iphone 10",
"slug": "iphone-10"
}
}
]