2017 © Pedro Peláez
 

library laravel-rateable

Allows multiple models to be rated with a fivestar like system.

image

devfelipereis/laravel-rateable

Allows multiple models to be rated with a fivestar like system.

  • Thursday, July 14, 2016
  • by felipereis
  • Repository
  • 2 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 34 Forks
  • 0 Open issues
  • 5 Versions
  • 22 % Grown

The README.md

Laravel Rateable

Build Status Latest Stable Version License, (*1)

Total Downloads Monthly Downloads Daily Downloads, (*2)

FOR PERSONAL USE. DON'T USE THIS FORK. USE: https://github.com/willvincent/laravel-rateable, (*3)

Provides a trait to allow rating of multiple models within your app for Laravel 5., (*4)

Ratings could be fivestar style, or simple +1/-1 style., (*5)

Installation

Edit your project's composer.json file to require willvincent/laravel-rateable., (*6)

"require": {
  "willvincent/laravel-rateable": "~1.0"
}

Next, update Composer from the terminal., (*7)

composer update

As with most Laravel packages you'll need to register Rateable service provider. In your config/app.php add 'willvincent\Rateable\RateableServiceProvider' to the end of the $providers array., (*8)

'providers' => [

    Illuminate\Foundation\Providers\ArtisanServiceProvider::class,
    Illuminate\Auth\AuthServiceProvider::class,
    ...
    willvincent\Rateable\RateableServiceProvider::class,

],

Getting started

After the package is correctly installed, you need to generate the migration., (*9)

php artisan rateable:migration

It will generate the <timestamp>_create_ratings_table.php migration. You may now run it with the artisan migrate command:, (*10)

php artisan migrate

After the migration, one new table will be present, ratings., (*11)

Usage

You need to set on your model that it is rateable., (*12)

<?php namespace App;

use willvincent\Rateable\Rateable;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{

    use Rateable;

}

Now, your model has access to a few additional methods., (*13)

First, to add a rating to your model:, (*14)

$post = Post::first();

$rating = new willvincent\Rateable\Rating;
$rating->rating = 5;
$rating->user_id = \Auth::id();

$post->ratings()->save($rating);

dd(Post::first()->ratings);

Once a model has some ratings, you can fetch the average rating:, (*15)

$post = Post::first();

dd($post->averageRating);
// $post->averageRating() also works for this.

Also, you can fetch the rating percentage. This is also how you enforce a maximum rating value., (*16)

$post = Post::find();

dd($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.

// $post->ratingPercent(5) -- Five star rating system totally equivilent to:
// $post->ratingPercent()

The Versions

14/07 2016

dev-master

9999999-dev

Allows multiple models to be rated with a fivestar like system.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Will Vincent

laravel laravel 5 rating vote rateable fivestar

08/02 2016

1.0.3

1.0.3.0

Allows multiple models to be rated with a fivestar like system.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Will Vincent

laravel laravel 5 rating vote rateable fivestar

14/10 2015

1.0.2

1.0.2.0

Allows multiple models to be rated with a fivestar like system.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Will Vincent

laravel laravel 5 rating vote rateable fivestar

27/08 2015

1.0.1

1.0.1.0

Allows multiple models to be rated with a fivestar like system.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Will Vincent

laravel laravel 5 rating vote rateable fivestar

27/08 2015

1.0

1.0.0.0

Allows multiple models to be rated with a fivestar like system.

  Sources   Download

MIT

The Requires

 

The Development Requires

by Will Vincent

laravel laravel 5 rating vote rateable fivestar