3 namespace App\Http\Controllers;
5 use App\Events\ApplicationAdded;
6 use App\Models\Application;
7 use App\Models\Tournament;
8 use Illuminate\Auth\Access\AuthorizationException;
9 use Illuminate\Http\Request;
11 class TournamentController extends Controller
14 public function apply(Request $request, Tournament $tournament) {
15 $this->authorize('apply', $tournament);
16 $application = new Application();
17 $application->tournament_id = $tournament->id;
18 $application->user_id = $request->user()->id;
20 ApplicationAdded::dispatch($application);
21 return $tournament->toJson();
24 public function single(Request $request, $id) {
25 $tournament = Tournament::with(
33 $this->authorize('view', $tournament);
34 foreach ($tournament->rounds as $round) {
36 $this->authorize('seeResults', $round);
37 } catch (AuthorizationException) {
38 $round->hideResults();
41 return $tournament->toJson();