2017 © Pedro Peláez
 

library laravel-ratings

Laravel Ratings Engine

image

se468/laravel-ratings

Laravel Ratings Engine

  • Wednesday, April 11, 2018
  • by se468
  • Repository
  • 2 Watchers
  • 1 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel Ratings Engine

Latest Stable Version Total Downloads License, (*1)

Ratings engine for Laravel using polymorphic relationships., (*2)

DEMO : here, (*3)

Installation

  1. composer require se468/laravel-ratings
  2. php artisan migrate to migrate the tables
  3. Add CanReceiveRatings trait to your model that receives Ratings (App\User, App\Company, App\Project .. whatever you need to receive ratings for) and implement RatingReceivable interface to the model.
  4. Add CanGiveRatings trait to your model that needs to give Ratings (Usually App\User).

Example (CanGiveRatings):, (*4)

<?php
namespace App;
use se468\Ratings\RatingGivable;
...

class User extends Authenticatable
{
    use CanGiveRating;

    ...
}

Example (CanReceiveRatings):, (*5)

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use se468\Ratings\RatingReceivable;
use se468\Ratings\Traits\CanReceiveRating;
...

class Company extends Model implements RatingReceivable
{
    use CanReceiveRating;

    ...
}

Usage

Basic Usage Example

public function rateCompany(Request $request)
{
    $input = $request->all();
    $company = Company::find($input["id"]);

    auth()->user()->rate($company, $input["rating"], 'Some Comment');

    return redirect()->back();
}

CanReceiveRatings Trait

Getting all ratings:

ratingsReceived() - morphMany to Ratings

Getting overall (average) rating:

getOverallRating() 

CanGiveRatings Trait

Getting ratings given by this:

ratingsGiven() - hasMany to Ratings

Giving a rating:

rate(RatingReceivable $ratable, $ratingValue)

Rating

You can change rater function in Rating model if you want something other than App\User to give ratings., (*6)

The Versions

11/04 2018

dev-master

9999999-dev

Laravel Ratings Engine

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel package

11/04 2018

v0.0.1

0.0.1.0

Laravel Ratings Engine

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel package