示例#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]);
                 }
             }
         }
     }
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $this->team = Team::findOrFail($this->route('team'));
     return Session::group()->id == $this->team->teamSet->group_id;
 }
示例#5
0
 /**
  * @test
  */
 public function canReorderPlayers()
 {
     $group = Group::findOrFail(2);
     $this->withSession([SessionManager::GROUP => $group->toArray()]);
     $teamSet = TeamSet::findOrFail(1);
     $team = $teamSet->teams->get(2);
     $startingPlayerOrder = [$team->players->first()->id, $team->players->get(1)->id];
     $this->post('/teams/' . $team->id . '/updateOrder', ['sortOrder' => [$startingPlayerOrder[1], $startingPlayerOrder[0]]])->assertResponseOk();
     $team = Team::findOrFail($team->id);
     $this->assertEquals($startingPlayerOrder[1], $team->players->first()->id);
     $this->assertEquals($startingPlayerOrder[0], $team->players->get(1)->id);
 }