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'); }
public function downvote($propositionId, $userId, $schoolEmail) { return Votes::create(["proposition_id" => $propositionId, "vote_user" => $userId, "vote_value" => 0, "vote_school_email" => $schoolEmail]); }
/** * 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'); }