/** * Run the database seeds. * * @return void */ public function run() { DB::table('match_games')->delete(); MatchGame::create(['match_id' => 955, 'game_id' => 1, 'game_num' => 1]); MatchGame::create(['match_id' => 955, 'game_id' => 2, 'game_num' => 2]); MatchGame::create(['match_id' => 972, 'game_id' => 3, 'game_num' => 1]); MatchGame::create(['match_id' => 972, 'game_id' => 4, 'game_num' => 2]); MatchGame::create(['match_id' => 970, 'game_id' => 5, 'game_num' => 1]); MatchGame::create(['match_id' => 970, 'game_id' => 6, 'game_num' => 2]); /** Alexandra H. at 2015 Battle Alamo tid: 13654 **/ /** PRO */ /** Round 1 */ MatchGame::create(['match_id' => 499, 'game_id' => 7, 'game_num' => 1]); MatchGame::create(['match_id' => 499, 'game_id' => 8, 'game_num' => 2]); MatchGame::create(['match_id' => 499, 'game_id' => 9, 'game_num' => 3]); /** Round 2 */ MatchGame::create(['match_id' => 1043, 'game_id' => 10, 'game_num' => 1]); MatchGame::create(['match_id' => 1043, 'game_id' => 11, 'game_num' => 2]); MatchGame::create(['match_id' => 1043, 'game_id' => 12, 'game_num' => 3]); MatchGame::create(['match_id' => 1043, 'game_id' => 13, 'game_num' => 4]); /** Open Round 1 */ MatchGame::create(['match_id' => 1024, 'game_id' => 14, 'game_num' => 1]); MatchGame::create(['match_id' => 1024, 'game_id' => 15, 'game_num' => 2]); /** Open Round 2 */ MatchGame::create(['match_id' => 628, 'game_id' => 16, 'game_num' => 1]); MatchGame::create(['match_id' => 628, 'game_id' => 17, 'game_num' => 2]); /** Open Round 3 */ MatchGame::create(['match_id' => 308, 'game_id' => 18, 'game_num' => 1]); MatchGame::create(['match_id' => 308, 'game_id' => 19, 'game_num' => 2]); /** Open Round 4 */ MatchGame::create(['match_id' => 1022, 'game_id' => 20, 'game_num' => 1]); MatchGame::create(['match_id' => 1022, 'game_id' => 21, 'game_num' => 2]); }
/** * Update a match * * @param int $id * @return Response */ public function updateMatch($league_id, $match_id) { $match_date = Input::get('match_date'); $player1_id = Input::get('player1_id'); $player2_id = Input::get('player2_id'); $p1_score = Input::get('p1_score'); $p2_score = Input::get('p2_score'); $match_date = new \DateTime($match_date); $match_date = $match_date->format("Y-m-d h:m:s"); if (!is_null($player1_id) && !is_null($player2_id)) { //update match $match = Match::find($match_id); if (!is_null($match)) { $match->player1_id = $player1_id; $match->player2_id = $player2_id; $match->match_date = $match_date; if ($p1_score > $p2_score) { $match->winner_id = $player1_id; } else { $match->winner_id = $player2_id; } $match->save(); //Find the game $match_game = MatchGame::find($match_id); $game = new Game(); if (!is_null($match_game)) { $game = Game::find($match_game->game_id); } else { //Game doesnt exist. create record in match games $game->save(); $match_game = new MatchGame(); $match_game->match_id = $match_id; $match_game->game_id = $game->id; } // update the game $game->score1 = $p1_score; $game->score2 = $p2_score; $game->save(); } } //Redirect to add more matches; add Save Message return \Redirect::route('tools.league.match.edit', array($league_id, $match_id))->with('success', 'Match updated Successfully'); }