public function index_onDelete() { if (($checkedIds = post('checked')) && is_array($checkedIds) && count($checkedIds)) { foreach ($checkedIds as $pollId) { if (!($poll = PollModel::find($pollId))) { continue; } $poll->delete(); if (!($votes = Vote::where('poll_id', $pollId))) { continue; } $votes->delete(); } Flash::success('The Poll has been deleted successfully.'); } return $this->listRefresh(); }
public function onPoll() { $this->request = Request::createFromGlobals(); $rules = ['vote_answer' => 'required']; $validation = Validator::make(post(), $rules); if ($validation->fails()) { throw new ValidationException($validation); } else { $addVote = new Votes(); $addVote->ip = $this->request->getClientIp(); $addVote->poll_id = post('id') == 0 ? Poll::getLatestPollId() : post('id'); $addVote->answer_id = \Input::get('vote_answer'); $addVote->save(); $this->page['vote'] = new Votes(); $this->lastestPoll = $this->page['lastestPoll'] = Poll::getLatestPoll(post('id') == 0 ? Poll::getLatestPollId() : post('id')); $this->lastestPollAnswers = $this->page['lastestPollAnswers'] = Poll::getLatestPollAnswers(post('id') == 0 ? Poll::getLatestPollId() : post('id')); $this->vote = $this->page['barColor'] = Settings::get('poll_settings'); } }