public function index($name) { $team = new Team(); if (!$team->where('team_name', $name)->first()) { return redirect()->back(); } $res = $team->join('fantasy_user_players', 'fantasy_teams.team_id', '=', 'fantasy_user_players.team_id')->join('fantasy_players', 'fantasy_user_players.id', '=', 'fantasy_players.player_id')->where('team_name', $name)->get(); return view('front.test')->with('team', $res); }
public function storeteamscores(Request $request) { $teams = new Team(); $teamsInfo = $teams->join('fantasy_user_players', 'fantasy_teams.team_id', '=', 'fantasy_user_players.team_id')->join('fantasy_match_scores', 'fantasy_user_players.id', '=', 'fantasy_match_scores.contract_id')->select('fantasy_teams.team_id', 'fantasy_teams.team_name', 'fantasy_teams.team_points', 'fantasy_user_players.match_player', 'fantasy_user_players.id as contract_id', 'fantasy_match_scores.match_id', 'fantasy_match_scores.points')->get(); $teamPoints = []; foreach ($teams->select('team_id', 'team_points as points')->get() as $team) { //$teamPoints = array_add($teamPoints, $team->team_id, $team->points); $teamPoints[] = ['team_id' => $team->team_id, 'points' => $team->points]; } //team_id, match_id, contract_id, points foreach ($teamsInfo as $teamPlayer) { $fantasyScores = new FantasyScores(); if ($teamPlayer->match_player == 1 && !$fantasyScores->where('match_id', $teamPlayer->match_id)->where('contract_id', $teamPlayer->contract_id)->first()) { $fantasyScores->team_id = $teamPlayer->team_id; $fantasyScores->match_id = $teamPlayer->match_id; $fantasyScores->contract_id = $teamPlayer->contract_id; $fantasyScores->points = $teamPlayer->points; $fantasyScores->save(); //$teamPoints[$teamPlayer->team_id] += $teamPlayer->points; foreach ($teamPoints as $teamPoint => $value) { if ($teamPoints[$teamPoint]['team_id'] == $teamPlayer->team_id) { $teamPoints[$teamPoint]['points'] += $teamPlayer->points; } } } } /*foreach ($teamPoints as $teamPoint => $value) { $teamPoints[$teamPoint]['points'] = $teamPoint['points'] + 10; }*/ foreach ($teamPoints as $key => $value) { DB::table('fantasy_teams')->where('team_id', $teamPoints[$key]['team_id'])->update(['team_points' => $teamPoints[$key]['points']]); } //$teamPoints = $teams->where('team_id', $teamPoints[$teams->team_id])->get(); return view('back.scores.index')->with('error', '')->with('qq', $teamPoints); }