Ratings and reviews for the Laravel's Eloquent models ⭐⭐⭐⭐⭐

Overview

Build Status

Laravel Reviews

Ratings and reviews for the Laravel's Eloquent models

laravel-reviews

Users will be able to rate and review the reviewable models. Then these reviews can be approved and be shown.

You will be able to load the ratings average and count on a reviewable model and display them.

It will provide the ability to sort the reviewables based on their ratings average using the Bayesian formula.

Installation And Setup

composer require mtvs/laravel-reviews

Then publish the files that are supposed to be in your codebase in order to be customizable by you. They're the review model, its database migration, its database factory, the HTTP controller and the config file.

php artisan vendor:publish

Next in your routes file, call the following macro on the router to register the default routes. You can use artisan route:list to see the routes.

Route::reviews();

Then, if you want to use the UI components, run the following command to install them. The components are written using Vue and Bootstrap.

The command also installs a stylesheet and a pack of font icons in the public directory to be used by the components. Don't forget to include the stylesheet in your views layout file.

php artisan reviews:ui

If you haven't enabled the auto registration in the app.js file, you need to register the components manually.

Vue.component('reviews', require('./components/reviews/Reviews.vue').default);
Vue.component('reviews-current', require('./components/reviews/ReviewsCurrent.vue').default);
Vue.component('reviews-form', require('./components/reviews/ReviewsForm.vue').default);
Vue.component('reviews-list', require('./components/reviews/ReviewsList.vue').default);
Vue.component('reviews-pagination', require('./components/reviews/ReviewsPagination.vue').default);
Vue.component('reviews-single', require('./components/reviews/ReviewsSingle.vue').default);
Vue.component('reviews-stars', require('./components/reviews/ReviewsStars.vue').default);

Vue.component('approval-status', require('./components/approval/ApprovalStatus.vue').default);
Vue.component('approval-buttons', require('./components/approval/ApprovalButtons.vue').default);

Now let's setup the models. There are some traits that are meant to be imported in the review model, the user model and also the model(s) that are going to be reviewed. The review model's trait has already been imported in it when it was installed. But the other traits need to be installed manually.

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Mtvs\Reviews\PerformsReviews;

class User extends Authenticatable
{
	use PerformsReviews;
}
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Mtvs\Reviews\Reviewable;

class Product extends Model
{
    use Reviewable;
}

You also have to specify the reviewable models in the reviews config file.

'reviewables' => [
	\App\Models\Product::class,	
],

Finally, remember to run the database migrations and compile the view components. You can also use the provided factory to seed the reviews.

Usage

The Ratings Component

To display the average and the count of a reviewable model's ratings, you can call <x-ratings>.

<x-ratings :average="$product->ratings_avg" :count="$product->ratings_count"/>

Do not forget to load those values on the model by calling loadRatings() on it or eager load them when making the query by calling withRatings().

The Reviews Component

To display the list of the reviews of a reviewable model and also the form to post them, you can call <x-reviews>.

<x-reviews :reviewable="$product"/>

It also contains a call to the <x-ratings>.

You can link the ratings component that you possibly use in the upper part of the page to the reviews component by wrapping the ratings in an <a href="reviews"> referring the reviews component.

Ranking Based on The Ratings

Reviewable models can be sorted based on their ratings when they're queried. To do so call the highestRated() on the query. It uses the Bayesian average formula to calculate the score of each model and sort them from the highest to the lowest score.

The Approval of Reviews

The review model uses Approvable trait from mtvs/eloquent-approval to enable to manage which reviews are allowed to be displayed.

You might also like...
This project is very diverse and based upon many languages and libraries such as C++, Python, JavaScript, PHP and MQTT

ADMS-Real-time-project This project is very diverse and based upon many languages and libraries such as C++, Python, JavaScript, PHP and MQTT Advance_

Private, self-hosted Composer/Satis repository with unlimited private and open-source packages and support for Git, Mercurial, and Subversion.
Private, self-hosted Composer/Satis repository with unlimited private and open-source packages and support for Git, Mercurial, and Subversion.

Private, self-hosted Composer/Satis repository with unlimited private and open-source packages and support for Git, Mercurial, and Subversion. HTTP API, HTTPs support, webhook handler, scheduled builds, Slack and HipChat integration.

YesilCMS is based on BlizzCMS and specifically adapted for VMaNGOS Core and includes new features and many bug fixes.
YesilCMS is based on BlizzCMS and specifically adapted for VMaNGOS Core and includes new features and many bug fixes.

YesilCMS · YesilCMS is based on BlizzCMS and specifically adapted for VMaNGOS Core and includes new features and many bug fixes. Features In addition

WPForms coding standards are based on the WordPress Coding Standards and the PHPCompatibility Coding Standards and help create strict and high-quality code.

WPForms coding standards are based on the WordPress Coding Standards and the PHPCompatibility Coding Standards and help create strict and high-quality code.

:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.
:globe_with_meridians: List of all countries with names and ISO 3166-1 codes in all languages and data formats.

symfony upgrade fixer • twig gettext extractor • wisdom • centipede • permissions handler • extraload • gravatar • locurro • country list • transliter

A redacted PHP port of Underscore.js with additional functions and goodies – Available for Composer and Laravel

Underscore.php The PHP manipulation toolbelt First off : Underscore.php is not a PHP port of Underscore.js (well ok I mean it was at first). It's does

:date: The VObject library for PHP allows you to easily parse and manipulate iCalendar and vCard objects

sabre/vobject The VObject library allows you to easily parse and manipulate iCalendar and vCard objects using PHP. The goal of the VObject library is

The Current US Version of PHP-Nuke Evolution Xtreme v3.0.1b-beta often known as Nuke-Evolution Xtreme. This is a hardened version of PHP-Nuke and is secure and safe. We are currently porting Xtreme over to PHP 8.0.3
The Current US Version of PHP-Nuke Evolution Xtreme v3.0.1b-beta often known as Nuke-Evolution Xtreme. This is a hardened version of PHP-Nuke and is secure and safe. We are currently porting Xtreme over to PHP 8.0.3

2021 Nightly Builds Repository PHP-Nuke Evolution Xtreme Developers TheGhost - Ernest Allen Buffington (Lead Developer) SeaBeast08 - Sebastian Scott B

Get mobile app version and other related data from Google Play Store, Apple App Store and Huawei AppGallery

Mobile App Version Get mobile app version and other related data from Google Play Store, Apple App Store and Huawei AppGallery. Installation Add to co

Owner
Mohamed Ali Tavasoli
Full-stack Web Developer - Experienced with @laravel - Available for remote work
Mohamed Ali Tavasoli
JSON schema models and generated code to validate and handle various data in PocketMine-MP

DataModels JSON schema models and generated code to validate and handle various data in PocketMine-MP This library uses php-json-schema-model-generato

PMMP 2 Nov 9, 2022
Rubix Server is a library for bringing your trained Rubix ML models into production.

Rubix Server is a library for bringing your trained Rubix ML models into production. Inference servers are stand-alone services that run on your private or public network and wrap your trained estimator in an API that can be queried locally or over the network in real-time using standard protocols. In addition, the library provides async-compatible client implementations for making queries to the server from your PHP applications.

Rubix 50 Aug 15, 2022
A system for auto-decorating models with presenters

Laravel Auto Presenter 7 This package automatically decorates objects bound to views during the view render process. Features Automatically decorate o

Laravel Auto Presenter 754 Dec 21, 2022
Shortest Path - have a function ShortestPath (strArr) take strArr which will be an array of strings which models a non-looping Graph.

Have the function ShortestPath(strArr) take strArr which will be an array of strings which models a non-looping Graph

null 1 Feb 5, 2022
Refresh artisan commands,table,migrations,models,controllers...

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Javier Fernández 11 Oct 18, 2022
Auto-expiring tags with additional payload data on any eloquent model.

Laravel TempTag Auto-expiring tags with additional payload data on any eloquent model. Installation first you need to install and configure mongodb in

masoud nazarpoor 2 Sep 18, 2021
Easily build Eloquent queries from API requests

Build Eloquent queries from API requests This package allows you to filter, sort and include eloquent relations based on a request. The QueryBuilder u

Spatie 3.5k Jan 7, 2023
A nice shortcut for group count queries with Eloquent / Laravel

Hightop PHP A nice shortcut for group count queries with Eloquent / Laravel Visit::top('browser'); // [ // 'Chrome' => 63, // 'Safari' => 50, //

Andrew Kane 3 Aug 24, 2022
Personal PHP MySQL query handler based on Eloquent using PDO.

?? Equivoluent Welcome to "Equivoluent" my personal PHP MySQL query handler using PDO. Equivoluent is based on Laravel's Eloquent. The goal of "Equivo

Wob Jelsma 2 Sep 7, 2022
MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query and get result in a fastest way

Mysql Optimizer mysql optimizer also known as MOP is a php query handling and manipulation library providing easy and reliable way to manipulate query

null 2 Nov 20, 2021