public function calcPoints() { //Get Tipps $tipps = Tipp::join('matches', 'tipps.match_id', '=', 'matches.id')->select('matches.id', 'matches.home_goals as erg1', 'matches.away_goals as erg2', 'tipps.*')->orderBy('date')->get(); //check points $count = count($tipps); for ($i = 0; $i < $count; $i++) { $points = 0; if ($tipps[$i]->home_goals === $tipps[$i]->erg1) { $points += 1; } if ($tipps[$i]->away_goals === $tipps[$i]->erg2) { $points += 1; } if ($tipps[$i]->home_goals - $tipps[$i]->away_goals === $tipps[$i]->erg1 - $tipps[$i]->erg2) { $points += 6; } if ($tipps[$i]->home_goals - $tipps[$i]->away_goals > 0 && $tipps[$i]->erg1 - $tipps[$i]->erg2 > 0) { $points += 4; } if ($tipps[$i]->home_goals - $tipps[$i]->away_goals < 0 && $tipps[$i]->erg1 - $tipps[$i]->erg2 < 0) { $points += 4; } if ($tipps[$i]->home_goals - $tipps[$i]->away_goals === 0 && $tipps[$i]->erg1 - $tipps[$i]->erg2 === 0) { $points += 4; } if ($tipps[$i]->home_goals === $tipps[$i]->erg1 && $tipps[$i]->away_goals === $tipps[$i]->erg2) { $points += 3; } if ($tipps[$i]->erg1 != null) { Tipp::where('id', $tipps[$i]->id)->update(['points' => $points]); } } return redirect('tipps'); }
public function getLatest() { Carbon::setlocale('de'); setlocale(LC_TIME, 'de_DE.utf8'); $userID = Auth::id(); $userIDExistsInTipps = Tipp::where('user_id', $userID)->first(); if ($userIDExistsInTipps) { $matches = Matches::where('league_id', 1)->where('date', '>', Carbon::now())->where('tipps.user_id', $userID)->join('clubs as homeclub', 'matches.home_id', '=', 'homeclub.id')->join('clubs as awayclub', 'matches.away_id', '=', 'awayclub.id')->join('tipps', 'tipps.match_id', '=', 'matches.id')->select('matches.*', 'homeclub.club as home', 'awayclub.club as away', 'tipps.home_goals as tipp_home', 'tipps.away_goals as tipp_away')->orderBy('date')->get(); return $matches; } else { $matches = Matches::where('league_id', 1)->where('date', '>', Carbon::now())->join('clubs as homeclub', 'matches.home_id', '=', 'homeclub.id')->join('clubs as awayclub', 'matches.away_id', '=', 'awayclub.id')->select('matches.*', 'homeclub.club as home', 'awayclub.club as away')->orderBy('date')->get(); return $matches; } }