This is the primary way that you can use to create a new vote to the model through User Model.
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}
This is how you can create a new vote-up to the $article model through User model.
1$user->voteUp($article);2// Returns Boolean
This is how you can create a new vote-down to the $article model through User model.
1$user->voteDown($article);2// Returns Boolean
This is how you can unvote the $article model through User model.
1$user->unvote($article);2// Returns Boolean
This is how you can check the $article model that has been voteed by User model.
1if($user->voted($article)) {2 //3}
This is the secondary way that you can use to create a new vote to the model.
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}
This is how you can create a new vote-up to the $article model.
1$article->voteUpBy($user);2// Returns Boolean
This is how you can create a new vote-down to the $article model.
1$article->voteDownBy($user);2// Returns Boolean
This is how you can unvote the $article model.
1$article->unvoteBy($user);2// Returns Boolean
This is how you can check the $article model that has been voteed.
1if($article->votedBy($user)) {2 //3}