public function save() { if (!$this->isValid()) { return false; } return DB::transaction(function () { $this->topic->update(['poll_last_vote' => Carbon::now()]); $this->topic->pollVotes()->where('vote_user_id', $this->params['user_id'])->delete(); foreach (array_unique($this->params['option_ids']) as $optionId) { $this->topic->pollVotes()->create(['poll_option_id' => $optionId, 'vote_user_id' => $this->params['user_id'], 'vote_user_ip' => $this->params['ip']]); } PollOption::updateTotals(['topic_id' => $this->topic->topic_id]); return true; }); }