1. Go to this page and download the library: Download nelkasovic/laravel-rating library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
nelkasovic / laravel-rating example snippets
use Nagy\LaravelRating\Traits\Rate\CanRate;
class User extends Model
{
use CanRate;
use Nagy\LaravelRating\Traits\Rate\Rateable;
class Post extends Model
{
use Rateable;
$user->rate($postModel, 5);
$user->unrate($postModel);
// alternatively
$user->rate($postModel, -1);
// or
$user->rate($postModel, false);
// or
$user->rate($postModel, null);
$post->ratingsAvg();
$post->ratingsCount();
$user->rated(); // returns a collection of rated models
use Nagy\LaravelRating\Traits\Vote\CanVote;
class User extends Model
{
use CanVote;
use Nagy\LaravelRating\Traits\Vote\Votable;
class Post extends Model
{
use Votable;
// up vote or +1 your model
$user->upVote($postModel);
// down vote or -1 your model
$user->downVote($postModel);
$postModel->votesCount();
$postModel->upVotesCount();
$postModel->downVotesCount();
$user->upVoted(); // returns a collection of up voted models
$user->downVoted(); // returns a collection of down voted models
$user->voted(); // returns a collection of total voted models;
use Nagy\LaravelRating\Traits\Like\CanLike;
class User extends Model
{
use CanLike;
use Nagy\LaravelRating\Traits\Like\Likeable;
class Post extends Model
{
use Likeable;
// like
$user->like($postModel);
// dislike
$user->dislike($postModel);
$postModel->likesCount();
$postModel->dislikesCount();
$postModel->likesDislikesCount();
$user->liked(); // return a collection of liked models;
$user->disliked(); // return a collection of disliked models;
$user->likedDisliked(); // return a collection of liked and disliked models;