2017 © Pedro Peláez
 

library eloquent-voteable

Polymorphic voting for Eloquent models

image

natzim/eloquent-voteable

Polymorphic voting for Eloquent models

  • Friday, October 16, 2015
  • by natzim
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Eloquent Voteable

Build Status GPA Code Coverage, (*1)

Installation

Install the package using composer, (*2)

composer require natzim/eloquent-voteable

Add the service provider to the providers array in config/app.php, (*3)

'providers' => [
    // ...
    Natzim\EloquentVoteable\VoteableServiceProvider::class
]

Publish the migrations, (*4)

php artisan vendor:publish

Run the migrations, (*5)

php artsain migrate

Documentation

In the code examples, $voter implements VoterInterface and $voteable implements VoteableInterface., (*6)

Voters

Voters are any model that can vote on voteables., (*7)

Voter models should implement VoterInterface and use Votes:, (*8)

use Natzim\EloquentVoteable\Contracts\VoterInterface;
use Natzim\EloquentVoteable\Traits\Votes;

class User extends Model implements VoterInterface
{
    use Votes;

    // ...
}

Methods

Get votes by a voter
$voter->votes;

Returns: Collection, (*9)

Vote on voteable
$voter->vote($voteable, 1); // Upvote $voteable

NOTE: Vote weights must be between -127 and 127, as it is stored as a tinyInteger, (*10)

Returns: Vote, (*11)

Vote up a voteable
$voter->upVote($voteable);

Returns: Vote, (*12)

Vote down a voteable
$voter->downVote($voteable);

Returns: Vote, (*13)

Cancel a vote on a voteable
$voter->cancelVote($voteable);

Returns: null, (*14)

Get the previous vote on a voteable
$voter->getVote($voteable);

Returns: Vote, (*15)

Voteables

Voteables are any model that can be voted on by voters., (*16)

Voteable classes should implement VoteableInterface and use Voteable:, (*17)

use Natzim\EloquentVoteable\Contracts\VoteableInterface;
use Natzim\EloquentVoteable\Traits\Voteable;

class Post extends Model implements VoteableInterface
{
    use Voteable;

    // ...
}

Methods

Get the score of a voteable
$voteable->score();

Returns: int, (*18)

Get votes on a voteable
$voteable->votes;

Returns: Collection, (*19)

Vote on a voteable
$voteable->voteBy($voter, 1); // Upvote $voteable

NOTE: Vote weights must be between -127 and 127, as it is stored as a tinyInteger, (*20)

Returns: Vote, (*21)

Vote up a voteable
$voteable->upVoteBy($voter);

Returns: Vote, (*22)

Vote down a voteable
$voteable->downVoteBy($voter);

Returns: Vote, (*23)

Cancel a vote on a voteable
$voteable->cancelVoteBy($voter);

Returns: null, (*24)

Get the previous vote by a voter
$voteable->getVoteBy($voter);

Returns: Vote, (*25)

The Versions

16/10 2015

dev-master

9999999-dev https://github.com/natzim/eloquent-voteable

Polymorphic voting for Eloquent models

  Sources   Download

MIT

The Requires

 

The Development Requires

voting vote

15/10 2015