/** * Run the database seeds. * * @return void */ public function run() { $timestamp = date('Y-m-d G:i:s'); $foods = [['name' => 'Rezanci Sicilijana', 'price' => '860', 'type' => 'meal', 'fats' => '500', 'proteins' => '', 'carbs' => '', 'eta' => '15', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Rižota z bučkami in gamberi', 'price' => '1080', 'type' => 'meal', 'fats' => '600', 'proteins' => '', 'carbs' => '', 'eta' => '15', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Ajdovi njoki z jurčki in tartufi', 'price' => '1380', 'type' => 'meal', 'fats' => '600', 'proteins' => '', 'carbs' => '', 'eta' => '15', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Espresso', 'price' => '140', 'type' => 'drink', 'fats' => '', 'proteins' => '', 'carbs' => '', 'eta' => '2', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Zeleni čaj', 'price' => '180', 'type' => 'drink', 'fats' => '', 'proteins' => '', 'carbs' => '', 'eta' => '2', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Tiramisu', 'price' => '480', 'type' => 'dessert', 'fats' => '', 'proteins' => '', 'carbs' => '', 'eta' => '2', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['name' => 'Čokoladni souffle', 'price' => '650', 'type' => 'dessert', 'fats' => '', 'proteins' => '', 'carbs' => '', 'eta' => '2', 'created_at' => $timestamp, 'updated_at' => $timestamp]]; \App\Food::insert($foods); $tables = [['number' => '1', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '2', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '3', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '4', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '5', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '6', 'created_at' => $timestamp, 'updated_at' => $timestamp], ['number' => '7', 'created_at' => $timestamp, 'updated_at' => $timestamp]]; \App\Table::insert($tables); }
/** * Saves matches into database * * */ public function storeGamesForm(SaveGamesRequest $request) { $input = $request->except('_token'); $count = count($input['match_id']); for ($i = 0; $i < $count; $i++) { if ($input['home_goals'][$i] != '') { DB::table('matches')->where('id', $input['match_id'][$i])->update(['home_goals' => $input['home_goals'][$i], 'away_goals' => $input['away_goals'][$i]]); } } // Update Tables .tables for ($i = 0; $i < $count; $i++) { if ($input['home_goals'][$i] != '') { // Update der Heimmannschaft $homePoints = 0; if ($input['home_goals'][$i] > $input['away_goals'][$i]) { $homePoints = 3; } elseif ($input['home_goals'][$i] === $input['away_goals'][$i]) { $homePoints = 1; } //TODO: Check if club_id exists in table if (Table::where('club_id', $input['home_id'][$i])->first() != NULL) { Table::where('club_id', $input['home_id'][$i])->update(['goals' => DB::raw('goals +' . $input['home_goals'][$i]), 'goals_against' => DB::raw('goals_against +' . $input["away_goals"][$i]), 'matchday_count' => DB::raw('matchday_count + 1'), 'points' => DB::raw('points + ' . $homePoints)]); } else { Table::insert(['club_id' => $input['home_id'][$i], 'goals' => DB::raw('goals +' . $input['home_goals'][$i]), 'goals_against' => DB::raw('goals_against +' . $input["away_goals"][$i]), 'matchday_count' => DB::raw('matchday_count + 1'), 'points' => DB::raw('points + ' . $homePoints), 'league_id' => $input['league'], 'season' => $input['season']]); } //Update der Auswärtsmannschaft $awayPoints = 0; if ($input['home_goals'][$i] < $input['away_goals'][$i]) { $awayPoints = 3; } elseif ($input['home_goals'][$i] == $input['away_goals'][$i]) { $awayPoints = 1; } if (Table::where('club_id', $input['away_id'][$i])->first() != NULL) { Table::where('club_id', $input['away_id'][$i])->update(['goals' => DB::raw('goals + ' . $input["away_goals"][$i]), 'goals_against' => DB::raw('goals_against + ' . $input["home_goals"][$i]), 'matchday_count' => DB::raw('matchday_count + 1'), 'points' => DB::raw('points + ' . $awayPoints)]); } else { Table::insert(['club_id' => $input['away_id'][$i], 'goals' => DB::raw('goals + ' . $input["away_goals"][$i]), 'goals_against' => DB::raw('goals_against + ' . $input["home_goals"][$i]), 'matchday_count' => DB::raw('matchday_count + 1'), 'points' => DB::raw('points + ' . $awayPoints), 'league_id' => $input['league'], 'season' => $input['season']]); } } } return redirect('spiele'); }