示例#1
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return mixed
  */
 public function destroy($id)
 {
     $canBeDeleted = empty(Fixture::find($id)->available_appointments->toArray());
     if ($canBeDeleted) {
         Fixture::destroy($id);
         \Flash::success('Fixture deleted!');
     } else {
         \Flash::error('Cannot delete because they are existing appointments for this fixture.');
     }
     return redirect('admin/data-management/fixtures');
 }
示例#2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $fixture_id
  * @return Response
  */
 public function update(Request $request, $fixture_id)
 {
     $fixture = Fixture::find($fixture_id);
     // Goals fields are empty
     //if($request->has(['home_team_id', 'away_team_id'])) {
     //        if(empty($request->home_team_goals) && empty($request->away_team_goals)) {
     //            $fixture->home_team_id = $request->home_team_id;
     //            $fixture->away_team_id = $request->away_team_id;
     //        }
     // Goals are isset
     if ($request->has(['home_team_goals', 'away_team_goals'])) {
         $fixture->home_team_goals = $request->home_team_goals;
         $fixture->away_team_goals = $request->away_team_goals;
         $home_previous = LeagueTable::where('team_id', $fixture->home_team_id)->orderBy('matchday', 'desc')->first();
         $away_previous = LeagueTable::where('team_id', $fixture->away_team_id)->orderBy('matchday', 'desc')->first();
         $home_current = $home_previous->replicate();
         $away_current = $away_previous->replicate();
         ++$home_current->matchday;
         ++$away_current->matchday;
         // Matches and points
         switch (true) {
             // Home team wins
             case $fixture->home_team_goals > $fixture->away_team_goals:
                 ++$home_current->matches_home_won;
                 ++$home_current->matches_won;
                 $home_current->points += 3;
                 ++$away_current->matches_away_lost;
                 ++$away_current->matches_lost;
                 break;
                 // Draw
             // Draw
             case $fixture->home_team_goals == $fixture->away_team_goals:
                 ++$home_current->matches_home_drawn;
                 ++$home_current->matches_drawn;
                 ++$home_current->points;
                 ++$away_current->matches_away_drawn;
                 ++$away_current->matches_drawn;
                 ++$away_current->points;
                 break;
                 // Away team wins
             // Away team wins
             case $fixture->home_team_goals < $fixture->away_team_goals:
                 ++$home_current->matches_home_lost;
                 ++$home_current->matches_lost;
                 ++$away_current->matches_away_won;
                 ++$away_current->matches_won;
                 $away_current->points += 3;
                 break;
         }
         // Goals
         switch (true) {
             // Home team doesn't score
             case $fixture->home_team_goals == 0:
                 ++$home_current->zero_for_home;
                 ++$home_current->zero_for;
                 ++$away_current->zero_against_away;
                 ++$away_current->zero_against;
                 break;
                 // Away team doesn't score
             // Away team doesn't score
             case $fixture->away_team_goals == 0:
                 ++$home_current->zero_against_home;
                 ++$home_current->zero_against;
                 ++$away_current->zero_for_away;
                 ++$away_current->zero_for;
                 break;
         }
         $home_current->goals_home_for += $fixture->home_team_goals;
         $home_current->goals_home_against += $fixture->away_team_goals;
         $home_current->goals_home_diff = $home_current->goals_home_for - $home_current->goals_home_against;
         $home_current->goals_for += $fixture->home_team_goals;
         $home_current->goals_against += $fixture->away_team_goals;
         $home_current->goals_diff = $home_current->goals_for - $home_current->goals_against;
         $away_current->goals_away_for += $fixture->away_team_goals;
         $away_current->goals_away_against += $fixture->home_team_goals;
         $away_current->goals_away_diff = $away_current->goals_away_for - $away_current->goals_away_against;
         $away_current->goals_for += $fixture->away_team_goals;
         $away_current->goals_against += $fixture->home_team_goals;
         $away_current->goals_diff = $away_current->goals_for - $away_current->goals_against;
         $home_current->save();
         $away_current->save();
     }
     $fixture->save();
     return response()->json(['success' => true]);
 }