Example #1
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);
});