コード例 #1
0
ファイル: Page.php プロジェクト: alex4ndru/proiectbitacad
 protected function addCountedVotes($petitions)
 {
     $i = 0;
     foreach ($petitions as $currentPetition) {
         $where = ['petitionId' => $currentPetition['id'], 'voteYes' => 1];
         $votesYes = count(Votes::where($where)->get()->toArray());
         $where = ['petitionId' => $currentPetition['id'], 'voteNo' => 1];
         $votesNo = count(Votes::where($where)->get()->toArray());
         $petitions[$i]['votesYes'] = $votesYes;
         $petitions[$i]['votesNo'] = $votesNo;
         $i++;
     }
     return $petitions;
 }
コード例 #2
0
 public function postVotes(Request $request)
 {
     $img_id = $request->get('image_id');
     $ip = $request->getClientIp();
     $exist = Votes::where('ip', $ip)->where('image_id', $img_id)->exists();
     if (!$exist) {
         $vote = Votes::create($request->all());
         $vote->ip = $ip;
         $vote->save();
         Session::flash('message', "Thank you for voting!");
         Session::flash('alert-class', 'alert-success');
     } else {
         Session::flash('message', "No cheating !!! You can't vote for the same image more then ONE time!!!");
         Session::flash('alert-class', 'alert-warning');
     }
     return redirect()->route('home');
 }
コード例 #3
0
ファイル: HomeController.php プロジェクト: usragung/E-Vote
 public function checkVoteStatus($username)
 {
     $vote = Votes::where(['username' => $username])->get();
     return $vote;
 }
コード例 #4
0
 /**
  * Update to increase the downvotes of a link.
  *
  * @param  int  $id
  * @return Response
  */
 public function downvote($id)
 {
     //retrieve entry for current link
     if (is_null(Votes::where(['userid' => Auth::user()->id, 'linkid' => $id])->first())) {
         $link = Links::find($id);
         $link->downvotes += 1;
         $link->save();
         $newVote = Votes::create(['linkid' => $id, 'userid' => Auth::user()->id, 'vote' => -1]);
         $newVote->save();
     } else {
         return redirect()->action('LinkController@index')->withErrors(['You have already voted.']);
     }
     return redirect()->action('LinkController@index');
 }