GithubHelp home page GithubHelp logo

minhkhoablieu / laravel-review-rateable Goto Github PK

View Code? Open in Web Editor NEW

This project forked from codebyray/laravel-review-rateable

0.0 0.0 0.0 59 KB

Review & Rating System For Lavavel 5, 6 & 7

License: MIT License

PHP 100.00%

laravel-review-rateable's Introduction

Laravel Review Rateable

Review Rateable system for laravel 5, 6, 7 & 8. You can rate your models by:

  • Overall Rating
  • Customer Service Rating
  • Quality Rating
  • Friendly Rating
  • Price Rating

You can also set whether the model being rated is recommended.

Installation

First, pull in the package through Composer.

composer require codebyray/laravel-review-rateable

And then include the service provider within app/config/app.php. Note: If you are running Laravel 5.5+ this will be auto loaded for you.

'providers' => [
    Codebyray\ReviewRateable\ReviewRateableServiceProvider::class
];

At last you need to publish and run the migration.

php artisan vendor:publish --provider="Codebyray\ReviewRateable\ReviewRateableServiceProvider" --tag="migrations"

Run the migration

php artisan migrate

Setup a Model

<?php

namespace App;

use Codebyray\ReviewRateable\Contracts\ReviewRateable;
use Codebyray\ReviewRateable\Traits\ReviewRateable as ReviewRateableTrait;
use Illuminate\Database\Eloquent\Model;

class Post extends Model implements ReviewRateable
{
    use ReviewRateableTrait;
}

Create a rating

When creating a rating you can specify whether the rating is approved or not by adding approved to the array. This is optional and if left out the default is not approved to allow for review before posting.

$user = User::first();
$post = Post::first();

$rating = $post->rating([
    'title' => 'This is a test title',
    'body' => 'And we will add some shit here',
    'customer_service_rating' => 5,
    'quality_rating' => 5,
    'friendly_rating' => 5,
    'pricing_rating' => 5,
    'rating' => 5,
    'recommend' => 'Yes',
    'approved' => true, // This is optional and defaults to false
], $user);

dd($rating);

Update a rating

$rating = $post->updateRating(1, [
    'title' => 'new title',
    'body' => 'new body',
    'customer_service_rating' => 1,
    'quality_rating' => 1,
    'friendly_rating' => 3,
    'pricing_rating' => 4,
    'rating' => 4,
    'recommend' => 'No',
    'approved' => true, // This is optional and defaults to false
]);

Marking review as approved

$rating = $post->updateRating(1, ['approved' => true]);

Delete a rating:

$post->deleteRating(1);

Fetch approved or not approved reviews/ratings for a particular resource

// Get approved ratings
$ratings = $post->getApprovedRatings($post->id, 'desc');

// Get not approved ratings
$ratings = $post->getNotApprovedRatings($post->id, 'desc');

// Get all ratings whether approved or not
$ratings = $post->getAllRatings($post->id, 'desc');

// Get the most recent ratings (limit and sort are optional)
// Limit default is 5, sort default is desc
$ratings = $post->getRecentRatings($post->id, 5, 'desc');

// Get the most recent user ratings (limit and sort are optional)
// Limit default is 5, approved default is true, sort default is desc
$userRatings = $post->getRecentUserRatings($user->id, 5, true, 'desc');

Fetch the average rating:

// Get Overall Average Rating
$post->averageRating()

// Get Customer Service Average Rating
$post->averageCustomerServiceRating()

// Get Quality Average Rating
$post->averageQualityRating()

// Get Friendly Average Rating
$post->averageFriendlyRating()

// Get Price Average Rating
$post->averagePricingRating()

or

$post->averageRating(2) //round to 2 decimal place
$post->averageRating(null, true) //get only approved average rating 

Get all ratings:

$post = Post::first();

$ratings = $post->getAllRatings($post->id);

Count total rating:

$post->countRating()

Fetch the rating percentage.

This is also how you enforce a maximum rating value.

$post->ratingPercent()

$post->ratingPercent(10)); // Ten star rating system
// Note: The value passed in is treated as the maximum allowed value.
// This defaults to 5 so it can be called without passing a value as well.

Note

This is a fork from Trexology's - Original Code - laravel-reviewRateable .

Please note that this code is not used in the original and is not maintained.

laravel-review-rateable's People

Contributors

codebyray avatar ecointest avatar ishodnikov avatar izshreyansh avatar jmspldnl avatar sundarocs avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.