public function add(AddTeam $request) { $tournament = Tournament::findOrFail($request->input('team.tournament')); if (Tournament::STATUS_DRAFT !== $tournament->status) { throw new LogicException('Team can be assigned only to tournament with draft status.'); } $team = TournamentTeam::create($request->input('team')); return $this->response->collection(TournamentTeam::where(['id' => $team->id])->get(), new TournamentTeamTransformer(), 'teams'); }
/** * @param $teams * @param $matches * @param $result * * @dataProvider matchesProvider */ public function testSerializerWithMatchesList($teams, $matches, $result) { /** * @var $tournament Tournament */ $tournament = Factory::create(Tournament::class); $league = Factory::create(League::class); for ($i = 1; $i <= $teams; $i++) { TournamentTeam::forceCreate(['id' => $i, 'tournamentId' => $tournament->id, 'teamId' => array_get(Factory::create(Team::class, ['leagueId' => $league->id]), 'id')]); } foreach ($matches as $key => $match) { Match::create(['tournamentId' => $tournament->id, 'homeTournamentTeamId' => $match['homeTeamId'], 'awayTournamentTeamId' => $match['awayTeamId'], 'homeScore' => $match['homeScore'], 'awayScore' => $match['awayScore'], 'homePenaltyScore' => 0, 'awayPenaltyScore' => 0, 'resultType' => $match['resultType'], 'gameType' => Match::GAME_TYPE_GROUP_STAGE, 'status' => Match::STATUS_FINISHED, 'round' => $key]); } $serializer = new StandingsSerializer(); $collection = $serializer->collection(Match::where(['tournamentId' => $tournament->id])->get()); foreach ($result as $teamScore) { $item = $collection->first(function ($key, $item) use($teamScore) { return $item['teamId'] == $teamScore['team']; }); $this->assertEquals($item['position'], $teamScore['position']); } }
public function remove($teamId, RemoveTeam $request) { return TournamentTeam::where(['id' => $teamId])->delete(); }
/** * Bootstrap the application services. * * @return void */ public function boot() { Tournament::observe(new TournamentObserver()); TournamentTeam::observe(new TournamentTeamObserver()); Match::observe(new MatchObserver()); }