X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FHttp%2FControllers%2FTournamentController.php;h=9d62c23bac3475f2becac58caca85296756c68bc;hb=3a774bb649734fc3a2135ec1b52cef9a049880ee;hp=c5bd40d84febb55ef3cb5fd3c632ee6c9f6e52b9;hpb=edd0e97bfdc544114f30bf4c13a929631c44a555;p=alttp.git diff --git a/app/Http/Controllers/TournamentController.php b/app/Http/Controllers/TournamentController.php index c5bd40d..9d62c23 100644 --- a/app/Http/Controllers/TournamentController.php +++ b/app/Http/Controllers/TournamentController.php @@ -2,20 +2,42 @@ namespace App\Http\Controllers; +use App\Events\ApplicationAdded; +use App\Models\Application; use App\Models\Tournament; +use Illuminate\Auth\Access\AuthorizationException; use Illuminate\Http\Request; class TournamentController extends Controller { + public function apply(Request $request, Tournament $tournament) { + $this->authorize('apply', $tournament); + $application = new Application(); + $application->tournament_id = $tournament->id; + $application->user_id = $request->user()->id; + $application->save(); + ApplicationAdded::dispatch($application); + 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(); }