se468 / laravel-ratings
Laravel Ratings Engine
Installs: 13
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/se468/laravel-ratings
Requires
- php: >=5.5.9
- illuminate/support: ~5.5
Requires (Dev)
- mockery/mockery: ~0.9.2|~1.0.0
- orchestra/testbench: ~3.0
- phpunit/phpunit: ~6.0
This package is not auto-updated.
Last update: 2025-12-15 15:37:03 UTC
README
Ratings engine for Laravel using polymorphic relationships.
DEMO : here
Installation
composer require se468/laravel-ratingsphp artisan migrateto migrate the tables- Add
CanReceiveRatingstrait to your model that receives Ratings (App\User,App\Company,App\Project.. whatever you need to receive ratings for) and implementRatingReceivableinterface to the model. - Add
CanGiveRatingstrait to your model that needs to give Ratings (UsuallyApp\User).
Example (CanGiveRatings):
<?php namespace App; use se468\Ratings\RatingGivable; ... class User extends Authenticatable { use CanGiveRating; ... }
Example (CanReceiveRatings):
<?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.