public function vote($score, $user, array $options = array()) { $score < CONFIG()->vote_record_min && ($score = CONFIG()->vote_record_min); $score > CONFIG()->vote_record_max && ($score = CONFIG()->vote_record_max); if ($user->is_anonymous()) { return false; } $vote = PostVote::where(['user_id' => $user->id, 'post_id' => $this->id])->first(); if (!$vote) { $vote = PostVote::create(array('post_id' => $this->id, 'user_id' => $user->id, 'score' => $score)); } $vote->updateAttributes(array('score' => $score)); $this->recalculate_score(); return true; }