示例#1
0
 /**
  * @param   $request
  * @param   $id
  *
  * @return mixed
  */
 public function store(TeamSetGroupOnlyRequest $request)
 {
     $request->merge(['team_set_id' => $request->route('teamset')]);
     $this->validate($request, ['name' => 'required']);
     $team = Team::create($request->except('_token'));
     return response()->json($team);
 }
示例#2
0
 /**
  * @return mixed
  */
 public function store(Request $request)
 {
     $request->merge(['group_id' => Session::group()->id, 'season_id' => Session::season()->id]);
     $this->validate($request, TeamSet::validationRules());
     DB::transaction(function () use($request) {
         $teamSet = TeamSet::create($request->except('teamSet'));
         // Copy the teams and players from the selected TeamSet
         if (is_numeric($request->input('teamSet')) && $request->input('teamSet') > 0) {
             $copyFrom = TeamSet::findOrFail($request->input('teamSet'));
             foreach ($copyFrom->teams as $copyFromTeam) {
                 $team = Team::create(['team_set_id' => $teamSet->id, 'name' => $copyFromTeam->name]);
                 $players = [];
                 foreach ($copyFromTeam->players as $player) {
                     $players[$player->id] = ['order' => $player->pivot->order];
                 }
                 if (count($players) > 0) {
                     $team->players()->attach($players);
                 }
             }
         }
     });
     return redirect('/teamsets')->withFlashSuccess('Teams have been added');
 }
示例#3
0
 private function seedTeamSet(Group $group)
 {
     $teamSet = TeamSet::create(['group_id' => $group->id, 'season_id' => $this->season->id, 'name' => 'League Teams']);
     $players = $group->players;
     for ($x = 1; $x <= 8; $x++) {
         $team = Team::create(['team_set_id' => $teamSet->id, 'name' => 'Team ' . $x]);
         $playerCount = $x <= 3 ? $x - 1 : 0;
         if ($playerCount > 0) {
             foreach ($players->random($playerCount) as $idx => $player) {
                 if (is_object($player)) {
                     $team->players()->attach($player->id, ['order' => $idx + 1]);
                 }
             }
         }
     }
 }