]> git.localhorst.tv Git - alttp.git/blob - app/Http/Controllers/RoundController.php
listen to round updates
[alttp.git] / app / Http / Controllers / RoundController.php
1 <?php
2
3 namespace App\Http\Controllers;
4
5 use App\Events\RoundAdded;
6 use App\Models\Protocol;
7 use App\Models\Round;
8 use App\Models\Tournament;
9 use Illuminate\Http\Request;
10
11 class RoundController extends Controller
12 {
13
14         public function create(Request $request) {
15                 $validatedData = $request->validate([
16                         'tournament_id' => 'required|exists:App\\Models\\Tournament,id',
17                 ]);
18                 $tournament = Tournament::findOrFail($validatedData['tournament_id']);
19                 $this->authorize('addRound', $tournament);
20
21                 $round = Round::create([
22                         'tournament_id' => $validatedData['tournament_id'],
23                 ]);
24
25                 Protocol::roundAdded(
26                         $tournament,
27                         $round,
28                         $request->user(),
29                 );
30
31                 RoundAdded::dispatch($round);
32
33                 return $round->toJson();
34         }
35
36 }