Pharaonic
Loading...

# User Model

This is the primary way that you can use to create a new vote to the model through User Model.

# Inclusion

You have to include the isVoter trait into the User Model.

1namespace App\Models;
2 
3use Illuminate\Foundation\Auth\User as Authenticatable;
4use Pharaonic\Laravel\Users\Traits\Actions\Vote\isVoter;
5 
6class User extends Authenticatable
7{
8 use isVoter;
9 
10 protected $fillable = ['name', 'email', 'password'];
11}

# voteUp

This is how you can create a new vote-up to the $article model through User model.

1$user->voteUp($article);
2// Returns Boolean

# voteDown

This is how you can create a new vote-down to the $article model through User model.

1$user->voteDown($article);
2// Returns Boolean

# unvote

This is how you can unvote the $article model through User model.

1$user->unvote($article);
2// Returns Boolean

# voted

This is how you can check the $article model that has been voteed by User model.

1if($user->voted($article)) {
2 //
3}

# Votable Model

This is the secondary way that you can use to create a new vote to the model.

# Inclusion

You have to include the isVotable trait into the Model.

1namespace App\Models;
2 
3use Illuminate\Database\Eloquent\Model;
4use Pharaonic\Laravel\Users\Traits\Actions\Vote\isVotable;
5 
6class Article extends Model
7{
8 use isVotable;
9 
10 protected $fillable = ['title'];
11}

# voteUpBy

This is how you can create a new vote-up to the $article model.

1$article->voteUpBy($user);
2// Returns Boolean

# voteDownBy

This is how you can create a new vote-down to the $article model.

1$article->voteDownBy($user);
2// Returns Boolean

# unvoteBy

This is how you can unvote the $article model.

1$article->unvoteBy($user);
2// Returns Boolean

# votedBy

This is how you can check the $article model that has been voteed.

1if($article->votedBy($user)) {
2 //
3}

# Relationships

  • votes
    • voter
    • votable
  • upVotes
    • voter
    • votable
  • downVotes
    • voter
    • votable