I need to get Auth::id() in my model to check if current user has voted. How to access to current user in Eloquent Model?
Model:
class Article extends Model {
protected $fillable = ['title', 'body', 'link'];
protected $appends = ['votesCount', 'isUserVoted'];
public function getIsUserVotedAttribute() {
return !!$this->votes()->where('user_id', \Auth::id())->first();
}
}
In getIsUserVotedAttribute method I get ID of null
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1qgJRrR
via IFTTT
Aucun commentaire:
Enregistrer un commentaire