Rate users, posts or other models with ease. You can even give a rating to a user for their role on other models i.e., post author or post illustator.
- installation
- Lumens
- Laravel
- Usage
- Giving a rating
- Getting a ratings of model
- Getting ratings aggregates
- Config
installation
- Laravel
- Lumens
Lumens
You can install this package via composer using this command:
Include service provider and config into bootstrap/app.php:
Laravel
You can install this package via composer using this command:
Add service provider:
Publish vendor files:
Usage
Giving a rating
In order to rate a model you need to access [RatingBuilder](#API of rating builder) instance. This can be done in several ways:
- By newing up instance manually:
- Via facade
- Via \Dorvidas\Ratings\RateableTrait trait method:
API of rating builder
- model($model) – set what you will give rating for. When using via trait this can be ommited, because we already know the model we will rate.
- give(5) – set the rating. The return value is \Dorvidas\Ratings\Models\Rating model.
- by($user) – set who is rating model. If skipped authorised user is used.
- on($model) – this is used to define what a user is rated for. Speaking in Laravel terminology we define on which model we rate a user. Below example of rating a user for post:
- as($role) – this is used to define what was a role of a user. Speaking in Laravel terminology we define which model’s column holds the user ID. If omitted it is expected that the column is user_id. An real life example could be giving different ratings for post author and illustrator:
Getting a ratings
Ratings are retrieved via \Dorvidas\Ratings\Rating model. Model ratings can be retrieved by querying ratings relations on a model. Relations is polymorphic.
sobar tetas folladas peludas
incesto gratis nenas peludas
trios x sol sanchez actriz porno
porno español trans pilladas sin bragas
vidios xxx sione cooper
xxporn jovencita caliente
videos putas maduras viejas calientes
vidio xxxx porno comic español
natalia sanchez desnuda videos porno peruano
vidiosxxx porno gay guarro
española folla shakira follando
gitanas follando maduras españolas anal
sexporno sexo gratis incesto
porni enanas porno
xxxespañol tetas puntiagudas
scat lesbianas follando española
pareja follando en la playa pormo
trio con gordas pajas en coche
porno gay chino trio amateur español
pollas corriendose videos caserosxxx
Don’t forget to add \Dorvidas\Ratings\MOdels\RateableTrait for it to work.
Rating model fields:
- model – name of the rated model.
- model_id – ID of rated model.
- on_model – this is usually used when we rate a User and want to define what for (on which model) we rate him i.e., on “Post”.
- on_model_id – ID of the model we rate model. If we rate use on “Post” this would be post ID.
- on_model_column – when rating using on model, with this we define what column defines user id. By default this is user_id.
- rated_by – ID of the user who rated.
- rating – actual rating.
Rating model query scopes:
- of – filter ratings of a model. It filter by model and model_id columns.
- on – filter ratings on specific model. It filter by on_model and on_model_id columns.
- as – filter ratings by role. It filter by on_model_column column.
- model – filter by model column.
- modelId – filter by model_id column.
- onModel – filter by model on_model column.
- onModelId – filter by on_model_id column.
Examples
An basic exampe of getting rating list of a “Post”:
If there is no model object, you can pass model ID and model type via scopes modelId and model:
If we want to get ratings of a user on specific model:
If we want to get ratings of a user on specific model for a specific role:
Getting rating aggregates
Rating aggregates are stored in table rating_aggregates. If class is using trait RateableTrait you can get aggregates by querying polymorphic relationship:
Whenever a rating is created an \Dorvidas\Ratings\Events\RatingCreatedEvent event is thrown. There is also a listener \Dorvidas\Ratings\Listeners\RecalculateRatingAggregatesListener which updates aggregate entry. So don’t forget to register those events and listener.
Config
- database_prefix – allows to add database prefix.








