Пример #1
0
 /**
  * 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');
 }