authorize('apply', $tournament); $application = new Application(); $application->tournament_id = $tournament->id; $application->user_id = $request->user()->id; $application->save(); ApplicationAdded::dispatch($application); Protocol::applicationReceived($tournament, $application, $request->user()); return $tournament->toJson(); } public function single(Request $request, $id) { $tournament = Tournament::with( 'applications', 'applications.user', 'rounds', 'rounds.results', 'participants', 'participants.user', )->findOrFail($id); $this->authorize('view', $tournament); foreach ($tournament->rounds as $round) { try { $this->authorize('seeResults', $round); } catch (AuthorizationException) { $round->hideResults(); } } return $tournament->toJson(); } public function open(Request $request, Tournament $tournament) { $this->authorize('update', $tournament); $tournament->accept_applications = true; $tournament->save(); TournamentChanged::dispatch($tournament); Protocol::tournamentOpenen($tournament, $request->user()); return $tournament->toJson(); } public function close(Request $request, Tournament $tournament) { $this->authorize('update', $tournament); $tournament->accept_applications = false; $tournament->save(); TournamentChanged::dispatch($tournament); Protocol::tournamentClosed($tournament, $request->user()); return $tournament->toJson(); } public function lock(Request $request, Tournament $tournament) { $this->authorize('update', $tournament); $tournament->locked = true; $tournament->save(); TournamentChanged::dispatch($tournament); Protocol::tournamentLocked($tournament, $request->user()); return $tournament->toJson(); } public function unlock(Request $request, Tournament $tournament) { $this->authorize('update', $tournament); $tournament->locked = false; $tournament->save(); TournamentChanged::dispatch($tournament); Protocol::tournamentUnlocked($tournament, $request->user()); return $tournament->toJson(); } }