public function vote(Request $request)
 {
     $profile = Profile::find($request->input('profile'));
     $location = (object) GeoIP::getLocation();
     if ($this->allowedToVote($location->ip) == true && $profile != null) {
         $profile->votes = $profile->votes + 1;
         $profile->save();
         // Save or update Voting table //
         $votes = Voting::where('ip_address', $location->ip)->first();
         if ($votes != null) {
             $votes->last_vote = Carbon::now();
             $votes->save();
             return redirect('/process?response=1&profile_id=' . $request->input('profile'));
         } else {
             $vote = Voting::create(['ip_address' => $location->ip, 'last_vote' => Carbon::now(), 'last_profile' => $request->input('profile'), 'geoip_tracking' => json_encode($location)]);
             if ($vote) {
                 return redirect('/process?response=2&profile_id=' . $request->input('profile'));
             }
             return redirect('/process?response=3');
         }
     }
     return redirect('/process?response=4');
 }
예제 #2
0
 /**
  * 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]]);
     }
 }