All Projects → renoki-co → Rating

renoki-co / Rating

Licence: apache-2.0
Laravel Eloquent Rating allows you to assign ratings to any model.

Projects that are alternatives of or similar to Rating

Laravel Likeable
Rate Eloquent models with Likes and Dislikes in Laravel. Development moved to Laravel Love package!
Stars: ✭ 95 (-45.71%)
Mutual labels:  eloquent, laravel, rating
Guardian
Eloquent Guardian is a simple permissions system for your users. While there are many other packages for permissions, this one solves everything in the most eloquent way.
Stars: ✭ 121 (-30.86%)
Mutual labels:  eloquent, laravel, model
Plans
Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.
Stars: ✭ 326 (+86.29%)
Mutual labels:  eloquent, laravel, model
Laravel Model Status
Easily add statuses to your models
Stars: ✭ 510 (+191.43%)
Mutual labels:  eloquent, laravel, model
Laravel Love
Add Social Reactions to Laravel Eloquent Models. It lets people express how they feel about the content. Fully customizable Weighted Reaction System & Reaction Type System with Like, Dislike and any other custom emotion types. Do you react?
Stars: ✭ 822 (+369.71%)
Mutual labels:  eloquent, laravel, rating
Laravel Reactions
Laravel reactions package for implementing reactions (eg: like, dislike, love, emotion, etc) on Eloquent models.
Stars: ✭ 58 (-66.86%)
Mutual labels:  eloquent, laravel, rating
Elasticsearch
The missing elasticsearch ORM for Laravel, Lumen and Native php applications
Stars: ✭ 375 (+114.29%)
Mutual labels:  eloquent, laravel, model
Befriended
Eloquent Befriended brings social media-like features like following, blocking and filtering content based on following or blocked models.
Stars: ✭ 596 (+240.57%)
Mutual labels:  eloquent, laravel, model
Eager Load Pivot Relations
Eager load pivot relations for Laravel Eloquent's BelongsToMany relation.
Stars: ✭ 134 (-23.43%)
Mutual labels:  eloquent, laravel, model
Laravel Sluggable
An opinionated package to create slugs for Eloquent models
Stars: ✭ 831 (+374.86%)
Mutual labels:  eloquent, laravel, model
Schedule
Schedule is a package that helps tracking schedules for your models. If you have workers in a company, you can set schedules for them and see their availability though the time.
Stars: ✭ 155 (-11.43%)
Mutual labels:  eloquent, laravel, model
Laravel Nullable Fields
Handles saving empty fields as null for Eloquent models
Stars: ✭ 88 (-49.71%)
Mutual labels:  eloquent, laravel
Laravel Prefixed Ids
Friendly prefixed IDs for Laravel models
Stars: ✭ 88 (-49.71%)
Mutual labels:  eloquent, laravel
Rating
rating system for laravel 5
Stars: ✭ 85 (-51.43%)
Mutual labels:  laravel, rating
Laravel Translatable
Making Eloquent models translatable
Stars: ✭ 1,390 (+694.29%)
Mutual labels:  eloquent, laravel
Sarala
Javascript library to communicate with RESTful API built following JSON API specification. inspired by Laravel’s Eloquent
Stars: ✭ 101 (-42.29%)
Mutual labels:  eloquent, laravel
Laravel Settings
Store key value pair in database as settings
Stars: ✭ 107 (-38.86%)
Mutual labels:  eloquent, laravel
Flattable
It helps you manage de-normalized tables
Stars: ✭ 81 (-53.71%)
Mutual labels:  eloquent, laravel
Laravel Cacheable
Rinvex Cacheable is a granular, intuitive, and fluent caching system for eloquent models. Simple, but yet powerful, plug-n-play with no hassle.
Stars: ✭ 107 (-38.86%)
Mutual labels:  eloquent, laravel
Searchable
Search/filter functionality for Laravel's Eloquent models
Stars: ✭ 113 (-35.43%)
Mutual labels:  eloquent, laravel

Laravel Eloquent Rating

CI codecov StyleCI Latest Stable Version Total Downloads Monthly Downloads License

Laravel Eloquent Rating allows you to assign ratings to any model, just like any other review based on stars.

🤝 Supporting

Renoki Co. on GitHub aims on bringing a lot of open source projects and helpful projects to the world. Developing and maintaining projects everyday is a harsh work and tho, we love it.

If you are using your application in your day-to-day job, on presentation demos, hobby projects or even school projects, spread some kind words about our work or sponsor our work. Kind words will touch our chakras and vibe, while the sponsorships will keep the open source projects alive.

ko-fi

🚀 Installation

Install the package:

$ composer require rennokki/rating

Publish the config:

$ php artisan vendor:publish --provider="Rennokki\Rating\RatingServiceProvider" --tag="config"

Publish the migrations:

$ php artisan vendor:publish --provider="Rennokki\Rating\RatingServiceProvider" --tag="migrations"

Preparing the model

To allow a model to rate other models, it should use the CanRate trait and implement the Rater contract.

use Rennokki\Rating\Traits\CanRate;
use Rennokki\Rating\Contracts\Rater;

class User extends Model implements Rater
{
    use CanRate;
    ...
}

The other models that can be rated should use CanBeRated trait and Rateable contract.

use Rennokki\Rating\Traits\CanBeRated;
use Rennokki\Rating\Contracts\Rateable;

class User extends Model implements Rateable
{
    use CanBeRated;
    ...
}

If your model can both rate & be rated by other models, you should use Rate trait and Rating contract.

use Rennokki\Rating\Traits\Rate;
use Rennokki\Rating\Contracts\Rating;

class User extends Model implements Rating
{
    use Rate;

    //
}

🙌 Usage

To rate other models, simply call rate() method:

$page = Page::find(1);

$user->rate($page, 10);
$user->hasRated($page); // true
$page->averageRating(User::class); // 10.0, as float

As a second argument to the rate() method, you can pass the rating score. It can either be string, integer or float.

To update a rating, you can call updateRatingFor() method:

$user->updateRatingFor($page, 9);
$page->averageRating(User::class); // 9.00, as float

As you have seen, you can call averageRating() within models that can be rated. The return value is the average arithmetic value of all ratings as float.

If we leave the argument empty, we will get 0.00 because no other Page model has rated the page so far. But since users have rated the page, we will calculate the average only from the User models, since only they have voted the page, strictly by passing the class name as the argument.

$page = Page::find(1);

$user1->rate($page, 10);
$user2->rate($page, 6);

$page->averageRating(); // 0.00
$page->averageRating(User::class); // 8.00, as float

While in our example, the User class can both rate and be rated, we can leave the argument empty if we reference to its class:

$user = User::find(1);

$user1->rate($user, 10);
$user2->rate($user, 6);

$user->averageRating(); // 8.00, as float
$user->averageRating(User::class); // 8.00, it is equivalent

The relationships are based on this too:

$page->raters()->get(); // Pages that have rated this page
$page->raters(User::class)->get(); // Users that have rated this page

$user->ratings()->get(); // Users that this user has rated
$user->ratings(Page::class)->get(); // Pages that this user has rated

🐛 Testing

vendor/bin/phpunit

🤝 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].