Пример #1
0
 public function store(Request $request)
 {
     $this->validate($request, ['postit_id' => 'required', 'value' => "required|integer"], ['required' => 'precisa :attribute', 'integer' => 'precisa ser numero :attribute']);
     $identity = $this->dispatch(new GetIdentity($request));
     $vote = Vote::firstOrNew(['postit_id' => $request->get('postit_id'), 'identifier_id' => $identity->id]);
     if ($vote->value == $request->value) {
         $vote->value = 0;
     } else {
         $vote->value = $request->value;
     }
     $vote->save();
     $vote->postIt->hasVoted = $vote->value;
     return $vote->postIt;
 }
Пример #2
0
 public function cancel($group_id, $discussion_id, $comment_id)
 {
     $vote = \App\Vote::firstOrNew(['comment_id' => $comment_id, 'user_id' => auth()->user()->id]);
     // if the vote was 1, we can decrement the total in the comment table
     if ($vote->vote == 1) {
         $comment = \App\Comment::findOrFail($comment_id);
         $comment->vote--;
         $comment->save();
     }
     // if the vote was -1, we can increment the total in the comment table
     if ($vote->vote == -1) {
         $comment = \App\Comment::findOrFail($comment_id);
         $comment->vote++;
         $comment->save();
     }
     $vote->vote = 0;
     $vote->save();
     return redirect()->back();
 }
Пример #3
0
        $row['ranking_date'] = $n->ranking_date;
        $row["{$compare_player_1->first_name}"] = intval($n->c1_ranking);
        $row["{$player->first_name}"] = intval($n->my_ranking);
        $row["{$compare_player_2->first_name}"] = intval($n->c2_ranking);
        array_push($arr_compare, $row);
    }
    $rankings = ["National" => $arr_national, "State" => $arr_state, "Compare" => $arr_compare];
    return $rankings;
});
Route::get('api/vote/castvote', function () {
    $skill_id = (int) Input::get('skillID');
    $voter_id = (int) Input::get('voterID');
    $for_id = (int) Input::get('forID');
    $against_id = (int) Input::get('againstID');
    //if $sameVote exists, do nothing
    $sameVote = Vote::where('voter_id', '=', $voter_id)->where('skill_id', '=', $skill_id)->where('for_id', '=', $for_id)->where('against_id', '=', $against_id)->count();
    if ($sameVote == 0) {
        $vote = Vote::firstOrNew(array('voter_id' => $voter_id, 'skill_id' => $skill_id, 'for_id' => $against_id, 'against_id' => $for_id));
        $vote->voter_id = $voter_id;
        $vote->skill_id = $skill_id;
        $vote->for_id = $for_id;
        $vote->against_id = $against_id;
        $vote->save();
    }
    // get the reults
    $p1 = Vote::head2head($skill_id, $for_id, $against_id);
    $p2 = Vote::head2head($skill_id, $against_id, $for_id);
    $versus = array("p1" => $p1, "p2" => $p2);
    //dd($versus);
    return Response::json($versus);
});