/** * Run the database seeds. * * @return void */ public function run() { $json = File::get(storage_path() . '/jsondata/votes.json'); $data = json_decode($json); foreach ($data as $obj) { Vote::create(array('id' => $obj->id, 'carId' => $obj->carId, 'votes' => $obj->votes, 'points' => $obj->points)); } }
public function store($topicId, Request $request) { $data = ['user_id' => Auth::user()->id, 'topic_id' => $topicId]; if (Vote::where($data)->count() > 0) { return response('', 204); } Vote::create($data); return response('', 200); }
public function update(Post $post) { if ($post->isVoted()) { return response([], 422); } Vote::create(['post_id' => $post->id, 'user_id' => Auth::user()->id]); $post->increment('vote_count'); return response([]); }
/** * Run the database seeds. * * @return void */ public function run() { DB::statement('SET FOREIGN_KEY_CHECKS = 0'); DB::table('votes')->delete(); DB::statement('SET FOREIGN_KEY_CHECKS = 1'); for ($i = 0; $i < 10000; $i++) { Vote::create(['candidate_id' => rand(78, 82)]); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request, ['vote' => 'required|array|vote_count|vote_unique|sane_votes']); $user = $request->user(); if ($user->uuid === null) { $user->update(['uuid' => uuid()]); } foreach ($request->get('vote') as $vote) { Vote::create(['candidate_id' => Candidate::findOrFail($vote)->id, 'user_id' => $user->id, 'term_id' => nextTerm()->id]); } Session::flash('message', 'Your votes were successfully counted.'); return redirect('/'); }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('votes')->delete(); //Voter 1 Julie vs Bernie Vote::create(['vote_id' => '1', 'voter_id' => '1', 'skill_id' => '1', 'for_id' => '192412', 'against_id' => '17446']); Vote::create(['vote_id' => '2', 'voter_id' => '1', 'skill_id' => '2', 'for_id' => '17446', 'against_id' => '192412']); Vote::create(['vote_id' => '3', 'voter_id' => '1', 'skill_id' => '3', 'for_id' => '17446', 'against_id' => '192412']); Vote::create(['vote_id' => '4', 'voter_id' => '1', 'skill_id' => '4', 'for_id' => '17446', 'against_id' => '192412']); Vote::create(['vote_id' => '5', 'voter_id' => '1', 'skill_id' => '5', 'for_id' => '17446', 'against_id' => '192412']); Vote::create(['vote_id' => '6', 'voter_id' => '1', 'skill_id' => '6', 'for_id' => '192412', 'against_id' => '17446']); Vote::create(['vote_id' => '7', 'voter_id' => '1', 'skill_id' => '7', 'for_id' => '17446', 'against_id' => '192412']); Vote::create(['vote_id' => '8', 'voter_id' => '1', 'skill_id' => '8', 'for_id' => '17446', 'against_id' => '192412']); Vote::create(['vote_id' => '9', 'voter_id' => '1', 'skill_id' => '9', 'for_id' => '192412', 'against_id' => '17446']); Vote::create(['vote_id' => '10', 'voter_id' => '1', 'skill_id' => '10', 'for_id' => '17446', 'against_id' => '192412']); //Voter 2 Julie vs Bernie Vote::create(['vote_id' => '11', 'voter_id' => '2', 'skill_id' => '1', 'for_id' => '192412', 'against_id' => '17446']); Vote::create(['vote_id' => '12', 'voter_id' => '2', 'skill_id' => '2', 'for_id' => '17446', 'against_id' => '192412']); Vote::create(['vote_id' => '13', 'voter_id' => '2', 'skill_id' => '3', 'for_id' => '192412', 'against_id' => '17446']); Vote::create(['vote_id' => '14', 'voter_id' => '2', 'skill_id' => '4', 'for_id' => '192412', 'against_id' => '17446']); Vote::create(['vote_id' => '15', 'voter_id' => '2', 'skill_id' => '5', 'for_id' => '17446', 'against_id' => '192412']); Vote::create(['vote_id' => '16', 'voter_id' => '2', 'skill_id' => '6', 'for_id' => '192412', 'against_id' => '17446']); Vote::create(['vote_id' => '17', 'voter_id' => '2', 'skill_id' => '7', 'for_id' => '17446', 'against_id' => '192412']); Vote::create(['vote_id' => '18', 'voter_id' => '2', 'skill_id' => '8', 'for_id' => '17446', 'against_id' => '192412']); Vote::create(['vote_id' => '19', 'voter_id' => '2', 'skill_id' => '9', 'for_id' => '192412', 'against_id' => '17446']); Vote::create(['vote_id' => '20', 'voter_id' => '2', 'skill_id' => '10', 'for_id' => '192412', 'against_id' => '17446']); //Voter 3 Julie vs Katie Vote::create(['vote_id' => '21', 'voter_id' => '3', 'skill_id' => '1', 'for_id' => '192412', 'against_id' => '172634']); Vote::create(['vote_id' => '22', 'voter_id' => '3', 'skill_id' => '2', 'for_id' => '172634', 'against_id' => '192412']); Vote::create(['vote_id' => '23', 'voter_id' => '3', 'skill_id' => '3', 'for_id' => '192412', 'against_id' => '172634']); Vote::create(['vote_id' => '24', 'voter_id' => '3', 'skill_id' => '4', 'for_id' => '192412', 'against_id' => '172634']); Vote::create(['vote_id' => '25', 'voter_id' => '3', 'skill_id' => '5', 'for_id' => '172634', 'against_id' => '192412']); Vote::create(['vote_id' => '26', 'voter_id' => '3', 'skill_id' => '6', 'for_id' => '192412', 'against_id' => '172634']); Vote::create(['vote_id' => '27', 'voter_id' => '3', 'skill_id' => '7', 'for_id' => '172634', 'against_id' => '192412']); Vote::create(['vote_id' => '28', 'voter_id' => '3', 'skill_id' => '8', 'for_id' => '192412', 'against_id' => '172634']); Vote::create(['vote_id' => '29', 'voter_id' => '3', 'skill_id' => '9', 'for_id' => '192412', 'against_id' => '172634']); Vote::create(['vote_id' => '30', 'voter_id' => '3', 'skill_id' => '10', 'for_id' => '192412', 'against_id' => '172634']); //Voter 4 Bernie vs Katie Vote::create(['vote_id' => '31', 'voter_id' => '4', 'skill_id' => '1', 'for_id' => '17446', 'against_id' => '172634']); Vote::create(['vote_id' => '42', 'voter_id' => '4', 'skill_id' => '2', 'for_id' => '17446', 'against_id' => '172634']); Vote::create(['vote_id' => '33', 'voter_id' => '4', 'skill_id' => '3', 'for_id' => '17446', 'against_id' => '172634']); Vote::create(['vote_id' => '34', 'voter_id' => '4', 'skill_id' => '4', 'for_id' => '17446', 'against_id' => '172634']); Vote::create(['vote_id' => '35', 'voter_id' => '4', 'skill_id' => '5', 'for_id' => '17446', 'against_id' => '172634']); Vote::create(['vote_id' => '36', 'voter_id' => '4', 'skill_id' => '6', 'for_id' => '172634', 'against_id' => '17446']); Vote::create(['vote_id' => '37', 'voter_id' => '4', 'skill_id' => '7', 'for_id' => '17446', 'against_id' => '172634']); Vote::create(['vote_id' => '38', 'voter_id' => '3', 'skill_id' => '8', 'for_id' => '17446', 'against_id' => '172634']); Vote::create(['vote_id' => '39', 'voter_id' => '4', 'skill_id' => '9', 'for_id' => '17446', 'against_id' => '172634']); Vote::create(['vote_id' => '40', 'voter_id' => '4', 'skill_id' => '10', 'for_id' => '17446', 'against_id' => '172634']); }
/** * Store a newly created resource in storage. * * NOTE: You are using a FormRequest without any sort of validation.. revise? * * @param Requests\VoteRequest|Request $request * @param $id * @return Response */ public function store(Requests\VoteRequest $request) { $postId = $request->input('postId'); $userId = $request->user()->id; $value = $request->input('value'); // Check to see if there is an existing vote $vote = Vote::wherePostId($postId)->whereUserId($userId)->first(); if (!$vote) { // First time the user is voting Vote::create(['post_id' => $postId, 'user_id' => $userId, 'value' => $value]); } else { $vote->value == $value ? $vote->delete() : $vote->update(['value' => $value]); } // AJAX JSON RESPONSE return response()->json(['status' => 'success', 'msg' => 'Vote has been added.']); }
/** * Run the database seeds. * * @return void */ public function run() { $faker = Faker\Factory::create('en_GB'); for ($i = 0; $i < 50; $i++) { for ($j = 0; $j < rand(0, 10); $j++) { if (rand(0, 1)) { $vote_up = 1; $vote_down = 0; } else { $vote_up = 0; $vote_down = 1; } \App\Vote::create(['user_id' => 1, 'movie_id' => $i, 'vote_up' => $vote_up, 'vote_down' => $vote_down]); } } }
public function processBallot(Request $request) { //mark as voted. $key = Key::where('key', $request->input('key'))->first(); $key->voted = true; $key->save(); $selected_candidates = $request->input('candidate'); if (sizeof($selected_candidates) != 9) { $message = "Vote won't be counted. You didn't chose the right number of candidates."; return view('form.success')->with('message', $message); } foreach ($request->input('candidate') as $id) { Vote::create(['candidate_id' => $id]); } $message = "Thanks for voting."; return view('form.success')->with('message', $message); }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { $params = $request->all(); $now = Carbon::now()->second(0)->minute(0); $end = Carbon::parse($now)->addDay($params['count_days']); $params['user_id'] = Auth::user()->id; $params['date_start'] = $now; $params['date_end'] = $end; $vote = Vote::create($params); if (array_key_exists('debate_id', $params)) { $debate = Debate::find((int) $params['debate_id']); $debate->vote_id = $vote->id; $debate->save(); Post::create(['user_id' => Auth::user()->id, 'debate_id' => $debate->id, 'message' => 'Un vote vient d\'être lancé. <a href="' . url('/forum/vote/' . $vote->id) . '">Venez voter !</a>']); } foreach ($params['choices'] as $choice) { Choice::create(['name' => $choice, 'vote_id' => $vote->id]); } return redirect('/forum/vote')->with('message', 'Vote créé avec succès.'); }
public function vote($product_id) { $user = Auth::user(); $user_id = $user->id; $vote = DB::table('votes')->where('user_id', '=', $user_id)->where('product_id', '=', $product_id)->get(); if ($vote) { return response()->json(['status' => 'Failed']); } else { $product = Product::find($product_id); $votes = $product->votes; $product->votes = $votes + 1; $product->save(); $vote = Vote::create(['user_id' => $user_id, 'product_id' => $product_id]); if ($vote) { return response()->json(['status' => 'success', 'votes' => $product->votes]); } else { return response()->json(['status' => 'Failed']); } } }
public function vote(Request $request) { $user = $request->get('CurrentUser'); $rate = $request->json()->get('rate'); $objectId = $request->json()->get('object_id'); $vote = Vote::create(['subject_id' => $user->id, 'object_id' => $objectId, 'rate' => $rate]); return Response::json(['vote' => $vote], 200); }
public function vote(Poll $poll, Request $request) { $user = Auth::user(); if (Vote::where('user_id', $user->id)->where('poll_id', $poll->id)->exists()) { return ['hasCallback' => 0, 'callback' => '', 'hasMsg' => 1, 'msgType' => 'danger', 'msg' => 'you have beed voted', 'returns' => '']; } Vote::create(['user_id' => $user->id, 'poll_id' => $poll->id, 'parameter_id' => $request->input('vote')]); Parameter::find($request->input('vote'))->addVote(); $parameters = $poll->parameters()->get(); $total_votes = $parameters->sum('num_vote'); if ($total_votes == 0) { $total_votes = 1; } return ['hasCallback' => 1, 'callback' => 'poll_voted', 'hasMsg' => 1, 'msg' => 'Voted Successfull', 'returns' => ['total_votes' => $total_votes, 'parameters' => $parameters]]; }
public static function vote(Request $request) { $voted = $request->voted; $uservote = Vote::where('iduser', $request->iduser)->where('idproblem', $request->idproblem)->first(); $problem = Problem::where('idproblem', $request->idproblem)->first(); if (empty($uservote)) { //no vote has been added yet by this user for this problem $vote = array('iduser' => $request->iduser, 'idproblem' => $request->idproblem, 'choice' => $voted); $vote = Vote::create($vote); switch ($voted) { case -1: $problem->votenegative++; break; case 1: $problem->votepositive++; break; } $problem->save(); return \Response::json('Done'); } else { // user's changing his vote if ($voted == 1) { switch ($uservote->choice) { case -1: $problem->votenegative -= 1; $problem->votepositive += 1; $uservote->choice = 1; break; case 0: $problem->votenegative += 1; $uservote->choice = 1; break; case 1: $problem->votepositive -= 1; $uservote->choice = 0; break; } } else { switch ($uservote->choice) { case -1: $problem->votenegative -= 1; $uservote->choice = 0; break; case 0: $problem->votenegative += 1; $uservote->choice = -1; break; case 1: $problem->votepositive -= 1; $problem->votenegative += 1; $uservote->choice = -1; break; } } $problem->save(); $uservote->save(); return \Response::json('Updated'); } return \Response::json('Error!'); }
/** * Saves the answers of a reading to the database * * @return mixed */ public function saveAnswers() { // Get voting id (doesn't check if a voting with that id exists because if it doesn't, vote creation will fail) $v_id = Input::get('voting'); // Get member/vote pairs $votes = Input::get('data'); // Get voting items of this voting and put their ids in another array to not make a lot of queries afterwards $votingItems = VotingItem::ofVoting($v_id)->get(); $votingItemIds = []; foreach ($votingItems as $vi) { $votingItemIds[] = $vi->id; } // Save votes to the database foreach ($votes as $vote) { // Check if a vote already exists (which means the user is changing the vote from the form) and delete it $prevVotes = Vote::where(['voting_id' => $v_id, 'member_id' => $vote['member_id']])->get(); if ($prevVotes->count() > 0) { foreach ($prevVotes as $v) { $v->delete(); // Delete vote for every voting item } } // Create the new vote foreach ($votingItemIds as $vItem_id) { // Make string which is the key to this voting item's answer in the $vote[] array $str = 'answer_for_' . $vItem_id; // If the key exists in the $vote[] array, save the vote to the database if (isset($vote[$str]) || array_key_exists($str, $vote)) { if ($vote[$str] == '') { $answer = null; } else { $answer = $vote[$str]; } // Save the vote to the database Vote::create(['voting_id' => $v_id, 'voting_item_id' => $vItem_id, 'member_id' => $vote['member_id'], 'answer_id' => $answer]); } } } // Return success json return Response::json('success', 200); }
public function vote(Request $request, $id) { $vote = Vote::where("question_id", $id)->where("user_id", \Auth::user()->id)->first(); if ($vote) { session()->flash('flash_msg', 'You have already voted for this poll.'); return redirect('/'); } $question = Question::find($id); $slug = $question->slug; $this->validate($request, [$slug => 'required'], ['required' => 'Select an option to vote.']); $choice = $question->choices()->where('choice_text', '=', $request->input($slug)); $choice->increment('votes'); $data["user_id"] = \Auth::user()->id; $data["question_id"] = $question->id; $data["choice_id"] = $choice->first()->id; Vote::create($data); session()->flash('flash_msg', 'You have voted successfully.'); return redirect('/'); }