]> git.localhorst.tv Git - alttp.git/blobdiff - app/Http/Controllers/TournamentController.php
application admin UI
[alttp.git] / app / Http / Controllers / TournamentController.php
index e563eac60bfb39c34a58e8da3da5a712a6ad14a6..6ef003837c1f5b99c1d4bf25003bec42706847ea 100644 (file)
@@ -2,6 +2,9 @@
 
 namespace App\Http\Controllers;
 
+use App\Events\ApplicationAdded;
+use App\Models\Application;
+use App\Models\Protocol;
 use App\Models\Tournament;
 use Illuminate\Auth\Access\AuthorizationException;
 use Illuminate\Http\Request;
@@ -9,8 +12,21 @@ 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);
+               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',