An open API service indexing awesome lists of open source software.

https://github.com/code4mk/lara-rating

Rating system for laravel project
https://github.com/code4mk/lara-rating

0devco code4mk laravel rating-system

Last synced: 10 months ago
JSON representation

Rating system for laravel project

Awesome Lists containing this project

README

          

# Rating system Laravel

Easily setup rating system in your laravel poject

# installation

```bash
composer require code4mk/lara-rating
```

# setup

## 1) vendor publish

```bash
php artisan vendor:publish --provider="Code4mk\LaraRate\LaraRateServiceProvider" --tag=config
php artisan vendor:publish --provider="Code4mk\LaraRate\LaraRateServiceProvider" --tag=migrations
```

## 2) config

* `config/laraRate.php`

```php
"rater_table_name" => "users",
"rater_retrive_columns" =>["id","email"]
```

* `php artisan config:clear`

# method

## `create()`

* `int $productID, int $raterID, int $rate, string $comment`

```php
use Krate;
Krate::create($productID,$userID,$rate,$comment)
```

## `update()`

* `int $productID, int $raterID, int $rate, string $comment`

```php
use Krate;
Krate::update($productID,$raterID,$rate,$comment);
```

## `getRatings()`

* get specific product's rating details
* `int productID`
```php
Krate::getRatings($productID);
```
* output

~ `Krate::getRatings(3)`

```json
[
{
"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"
}
}
]
```

## `getRatingStat()`

* rating type
* `int productID`
```php
Krate::getRatingStat($productID);
```

* output

~ `Krate::getRatingStat(3)`

```json
{
"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
}
```

## getRaterRatings

* customer/rater/user's rating lists
* `int raterID`

```php
Krate::getRaterRatings($raterID);
```

~ `Krate::getRaterRatings(2)`

```json
[
{
"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"
}
}
]
```