Download the PHP package agilepixels/laravel-rateable without Composer
On this page you can find all versions of the php package agilepixels/laravel-rateable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download agilepixels/laravel-rateable
More information about agilepixels/laravel-rateable
Files in agilepixels/laravel-rateable
Package laravel-rateable
Short Description A package to add ratings to Eloquent Models
License MIT
Homepage https://github.com/agilepixels/laravel-rateable
Rated 5.00 based on 1 reviews
Informations about the package laravel-rateable
Add ratings to Eloquent Models
Imagine you want to add star ratings to an Eloquent Model. This package enables that feature for you. Ratings can be from 0 to 5 stars, +1/-1 or any other range you like.
This package provides a HasRatings
and AddsRatings
traits that, once installed on a model, allows you to do things like this:
Installation
You can install the package via composer:
The migrations for the ratings are loaded automatically. You can migrate the ratings
table using:
A config file is included to specify the range for the ratings. By default, rating are between 0 and 5. However, you are free to use it otherwise. For instance, ratings like +1 or -1. You can publish the config-file with:
Using the trait
To enable the ratings for a model, use the AgilePixels\Rateable\Traits\HasRatings
trait on the model.
If you would like to calculate the ratings for the author model, you may use the AgilePixels\Rateable\Traits\AddsRatings
trait on your User model (or any other model that is able to add a rating).
Usage
The createRating Method
To create a rating for a model that HasRatings
, you can use the creatRating()
method. The method takes two variables: $rating
and $author
. The $rating
can be an integer or a float within the range defined in your config file (default is 0 to 5). The $author
refers to the model that AddsRatings
which, in most cases, is your User model.
Optionally, you can also post a comment for a rating. This can be done through a third string variable called $body
.
The createComment Method
Once a rating is created, you might want to respond to the rating as owner of the web application. This can be done using the createComment()
method. The method takes two variables: $author
and $body
.
Calculations
Of course, you may want to display some data about the models ratings. This package provides three methods to do so:
The data is also available as accessor. You may access the data like this:
Credits
License
The MIT License (MIT). Please see License File for more information.