Skip to content

code4mk/lara-rating

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rating system Laravel

Easily setup rating system in your laravel poject

installation

composer require code4mk/lara-rating

setup

1) vendor publish

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
"rater_table_name" => "users",
"rater_retrive_columns" =>["id","email"]
  • php artisan config:clear

method

create()

  • int $productID, int $raterID, int $rate, string $comment
use Krate;
Krate::create($productID,$userID,$rate,$comment)

update()

  • int $productID, int $raterID, int $rate, string $comment
use Krate;
Krate::update($productID,$raterID,$rate,$comment);

getRatings()

  • 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"
    }
  }
]

getRatingStat()

  • 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
}

getRaterRatings

  • 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"
        }
    }
]

Releases

No releases published

Packages

No packages published

Languages