3 namespace App\Http\Controllers;
5 use App\Events\ApplicationAdded;
6 use App\Models\Application;
7 use App\Models\Protocol;
8 use App\Models\Tournament;
9 use Illuminate\Auth\Access\AuthorizationException;
10 use Illuminate\Http\Request;
12 class TournamentController extends Controller
15 public function apply(Request $request, Tournament $tournament) {
16 $this->authorize('apply', $tournament);
17 $application = new Application();
18 $application->tournament_id = $tournament->id;
19 $application->user_id = $request->user()->id;
21 ApplicationAdded::dispatch($application);
22 Protocol::applicationReceived($tournament, $application, $request->user());
23 return $tournament->toJson();
26 public function single(Request $request, $id) {
27 $tournament = Tournament::with(
35 $this->authorize('view', $tournament);
36 foreach ($tournament->rounds as $round) {
38 $this->authorize('seeResults', $round);
39 } catch (AuthorizationException) {
40 $round->hideResults();
43 return $tournament->toJson();