2017 © Pedro Peláez
 

library laravel-rating

manage rating column for elqouent models

image

nagy/laravel-rating

manage rating column for elqouent models

  • Sunday, January 28, 2018
  • by mohamednagy
  • Repository
  • 1 Watchers
  • 4 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 133 % Grown

The README.md

                , (*1)

New Maintainer

This package now maintined by Ahmed Nagi, (*2)

Laravel-Ratings

Laravel package that allows you to rate, like & dislike or vote up & down your models with a simple and clear way.
If you see this packge can help, Don't skimp on me with a star :), (*3)

Rating

include CanRate trait into your user model to apply rating functions, (*4)

use Nagy\LaravelRating\Traits\Rate\CanRate;

class User extends Model
{
    use CanRate;

include Rateable trait to your model that will be rateable, (*5)

use Nagy\LaravelRating\Traits\Rate\Rateable;

class Post extends Model
{
    use Rateable;

now you can rate your models as the following:, (*6)

$user->rate($postModel, 5);

also you can unrate your models as the following:, (*7)

$user->unrate($postModel);

// alternatively
$user->rate($postModel, -1);
// or
$user->rate($postModel, false);
// or
$user->rate($postModel, null);

get the average ratings of a model, (*8)

$post->ratingsAvg();

get the total count of ratings of a model, (*9)

$post->ratingsCount();

get the rated models by a user, (*10)

$user->rated(); // returns a collection of rated models

Voting

include CanVote trait into your user model to apply rating functionalties, (*11)

use Nagy\LaravelRating\Traits\Vote\CanVote;

class User extends Model
{
    use CanVote;

include Votable trait to your model that will be votable, (*12)

use Nagy\LaravelRating\Traits\Vote\Votable;

class Post extends Model
{
    use Votable;

now you can vote your model as the following:, (*13)

// up vote or +1  your model
$user->upVote($postModel);

// down vote or -1 your model
$user->downVote($postModel);

get total votes count, (*14)

$postModel->votesCount();

get total up votes count, (*15)

$postModel->upVotesCount();

get total down votes count, (*16)

$postModel->downVotesCount();

get the up voted models by a user, (*17)

$user->upVoted(); // returns a collection of up voted models

get the down voted models by a user, (*18)

$user->downVoted(); // returns a collection of down voted models

get the total voted models by a user, (*19)

$user->voted(); // returns a collection of total voted models;

Like & Dislike

include CanLike trait into your user model to apply like and dislike functionalties, (*20)

use Nagy\LaravelRating\Traits\Like\CanLike;

class User extends Model
{
    use CanLike;

include Likeable trait to your model that will be likeable, (*21)

use Nagy\LaravelRating\Traits\Like\Likeable;

class Post extends Model
{
    use Likeable;

now you can like your model as the following:, (*22)

// like
$user->like($postModel);

// dislike
$user->dislike($postModel);

get total likes count, (*23)

$postModel->likesCount();

get total dislikes count, (*24)

$postModel->dislikesCount();

get total likes and dislikes count, (*25)

$postModel->likesDislikesCount();

get the liked models by a user, (*26)

$user->liked(); // return a collection of liked models;

get the disliked models by a user, (*27)

$user->disliked(); // return a collection of disliked models;

get the total liked and disliked models by a user, (*28)

$user->likedDisliked(); // return a collection of liked and disliked models;

Install

for laravel 8.* , 7.* , 6.*, (*29)

composer require nagy/laravel-rating

for laravel 5.*, (*30)

composer require nagy/laravel-rating:^1.2

in your config/app.php, (*31)

    'providers' => [
        ...
        Nagy\LaravelRating\LaravelRatingServiceProvider::class
    ],

    'aliases' => [
        ...
        "LaravelRating" => \Nagy\LaravelRating\LaravelRatingFacade::class,
    ]

You don't need this step in laravel5.5 package:discover will do the job :), (*32)

publish the migrations, (*33)

php artisan vendor:publish --tag=laravelRatings

run the migrations, (*34)

php artisan migrate

The Versions

28/01 2018

dev-master

9999999-dev

manage rating column for elqouent models

  Sources   Download

MIT

The Requires

 

The Development Requires

by Avatar mohamednagy

22/01 2018

v1.0

1.0.0.0

manage rating column for elqouent models

  Sources   Download

MIT

The Development Requires

by Avatar mohamednagy