Download the PHP package digikraaft/laravel-review-rating without Composer
On this page you can find all versions of the php package digikraaft/laravel-review-rating. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download digikraaft/laravel-review-rating
More information about digikraaft/laravel-review-rating
Files in digikraaft/laravel-review-rating
Package laravel-review-rating
Short Description Review & Rating system for Laravel
License MIT
Homepage https://github.com/digikraaft/laravel-review-rating
Informations about the package laravel-review-rating
Add Review and Rating Feature to your Laravel application
Review and Rating System for Laravel
This package provides a simple review and rating system for Laravel. It supports Laravel 5.8 an up. Here is a quick demonstration of how it can be used:
Installation
You can install the package via composer:
You must publish the migration with:
Run the migration to publish the reviews
table with:
You can optionally publish the config-file with:
The content of the file that will be published to config/review-rating.php
:
Usage
Add the HasReviewRating
trait to the model:
Create a review
To create a review, use the review
function of the trait.
Like this:
The first argument is the content of the review while the second argument is the author. This can be any Eloquent model.
To create a review with rating, pass in the rating value as the third argument of
the review
function. Valid values are int
s and float
s:
To create a review with rating and title, add the title as the fourth argument
of the review
function:
You can also check if user has reviewed the model by using the hasReviewed
function:
Retrieving reviews
You can get the last review like this:
The content of the review can be gotten like this:
To get the rating for the review, do this:
To get the title of the review:
All reviews can be retrieved like this:
To access each review from the reviews retrieved, do this:
The allReviews
scope can be used to retrieve all the reviews for all instances of a model:
Retrieving basic Review Stats
You can get the number of reviews a model has:
To get the number of reviews a model has received over a period,
pass in a Carbon
formatted $from
and $to
dates as the first and second
arguments respectively:
Note that an InvalidDate
exception will be thrown if the $from
date is later than the $to
You can get the number of ratings a model has:
To get the number of ratings a model has received over a period,
pass in a Carbon
formatted $from
and $to
dates as the first and second
arguments respectively:
To get the average rating a model has received:
The average rating that is returned is by default not rounded.
If you would like to round
the returned result, pass an integer value of the
decimal place you want it rounded to.
To get the average rating a model has received over a period,
pass in a Carbon
formatted $from
and $to
dates as the first and second
arguments respectively:
The withRatings
scope can be used to retrieve all the reviews that have a rating for all instances of a model:
Check if model has review
You can check if a model has at least one review:
Check if model has rating
You can check if a model has at least one rating:
Events
The Digikraaft\ReviewRating\Events\ReviewCreatedEvent
event will be dispatched when
a review has been created. You can listen to this event and take necessary actions.
An instance of the review will be passed to the event class and can be accessed for use:
Custom model and migration
You can change the model used by specifying a different class name in the
review_model
key of the review-rating
config file.
You can also change the column name used in the reviews
table
(default is model_id
) when using a custom migration. If this is the case,
also change the model_primary_key_attribute
key of the review-rating
config file.
Testing
Use the command below to run your tests:
More Good Stuff
Check here for more awesome free stuff!
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Tim Oladoyinbo
- All Contributors
License
The MIT License (MIT). Please see License File for more information.