Download the PHP package ghanem/rating without Composer

On this page you can find all versions of the php package ghanem/rating. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?
ghanem/rating
Rate from 1 - 5
Rated 4.50 based on 4 reviews

Informations about the package rating

Latest Stable Version License Total Downloads

Laravel Rating

Rating system for Laravel 8, 9, 10, 11, 12 & 13.

Using Filament? See ghanem/rating-filament — a star input field, a sortable average-rating table column, an infolist entry and a review moderation relation manager for Filament 4 & 5.

Installation

Upgrading from V12.0? That tag was a mis-tag: it read as "Laravel 12 support" but registered on Packagist as major version 12, so it outranked every 2.x release. It has been removed. If your composer.json says "ghanem/rating": "^12.0", change it to "^2.1" and run composer update ghanem/rating. No code changes are needed — v2.1.0 is the same line, plus Laravel 13 support and the migration publishing fixes.

The package uses Laravel's auto-discovery, so no need to manually register the service provider.

Getting started

Publish and run the migration:

Optionally publish the config file:

Usage

Setup a Model

Add the Ratingable trait to any model you want to be ratable:

Ratingable is a trait, not an interface. Put it in use inside the class body — never in implements. class Post extends Model implements Ratingable fails with "cannot implement Ratingable - it is not an interface".

Add the CanRate trait to the author model:

Create a rating

Create or update a unique rating

Only one rating per author per model:

Update a rating

Delete a rating

Rating with review body

Scoped ratings (rate different aspects)

Weighted ratings

Aggregates

All aggregate methods accept an optional $type parameter for scoped ratings:

All available as attributes too:

Author queries (CanRate)

Check if rated

Query scopes

Displaying ratings in Blade

The package is storage-only — it ships no views or assets, so you stay in control of your markup. Here is a complete 5-star setup with no JavaScript and no front-end dependencies.

1. Read-only stars

ratingPercent() already returns the average as a percentage of the maximum, which is exactly what a CSS clip needs. Fractional averages (3.7 stars) render correctly with no extra work.

For a 10-point scale, pass the max: $post->ratingPercent(10).

2. An interactive rating form

Radio inputs in reverse order, so the CSS sibling selector can highlight the hovered star and every star before it. Accessible and keyboard-operable, because it is a real radio group.

3. Route and controller

Validate in the request as well as configuring config/rating.php. The config bounds throw InvalidRatingException, which surfaces as a 500; request validation gives the user a normal field error instead.

4. Listing many rated models

Calling $post->avgRating() inside a loop runs one aggregate query per row. Load the aggregates with the query instead:

withAvgRating() selects a ratings_avg_rating alias and withCountRatings() selects ratings_count. Both are plain columns on the result, so sorting and filtering happen in SQL — see Query scopes.

Validation

Configure rating bounds in config/rating.php:

Invalid ratings throw Ghanem\Rating\Exceptions\InvalidRatingException.

Events

The package fires events on rating lifecycle:

Each event has a public $rating property with the Rating model.

Filament admin panel

ghanem/rating-filament (Packagist) adds Filament 4 & 5 components on top of this package:

Component Purpose
RatingInput Clickable star picker for forms, with validation bounds read from config/rating.php
RatingColumn Sortable average-rating column, backed by withAvgRating() so it does not N+1
RatingEntry Read-only stars for infolists
RatingsRelationManager Moderate the ratings and reviews a record received

Related packages

Testing

Credits

This package began life in 2015 as an MIT-licensed package by DraperStudio / PackageBackup, whose original repository is no longer published. It has been maintained by GAIT ever since, across Laravel 5 through 13. The original copyright notice is retained in LICENSE.

Sponsor

Become a Sponsor


All versions of rating with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^8.0|^9.0|^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package ghanem/rating contains the following files

Loading the files please wait ...