public function allowedToVote($ip) { $p = Voting::where('ip_address', $ip)->first(); if ($p != null) { $last_vote = new Carbon($p->last_vote); $diffInMinutes = (int) Carbon::now()->diffInSeconds($last_vote); if ($diffInMinutes > 299) { return true; } else { return false; } } return true; }
/** * Save a new voting to the database * * @param VotingRequest $request */ private function createVoting(VotingRequest $request) { // Make a voting and save it $v = Voting::create(['title' => $request->input('title'), 'completed' => false]); // Make voting items and save them $objectives = $request->input('objectives'); $types = $request->input('voting_types'); if (count($objectives) != count($types)) { // objectives and types should always have the same length because of the way the form is made return 'ERROR: Vote objectives and types length is different!'; } $count = count($objectives); for ($i = 0; $i < $count; $i++) { VotingItem::create(['voting_id' => $v->id, 'vote_type_id' => $types[$i], 'vote_objective_id' => $objectives[$i]]); } }