3 namespace App\Http\Controllers;
5 use App\Events\RoundAdded;
6 use App\Events\RoundChanged;
7 use App\Models\Protocol;
9 use App\Models\Tournament;
10 use Illuminate\Http\Request;
12 class RoundController extends Controller
15 public function create(Request $request) {
16 $validatedData = $request->validate([
17 'tournament_id' => 'required|exists:App\\Models\\Tournament,id',
19 $tournament = Tournament::findOrFail($validatedData['tournament_id']);
20 $this->authorize('addRound', $tournament);
22 $tournament->loadMax('rounds', 'number');
24 $round = Round::create([
25 'number' => intval($tournament->rounds_max_number) + 1,
26 'tournament_id' => $validatedData['tournament_id'],
35 RoundAdded::dispatch($round);
37 return $round->toJson();
40 public function setSeed(Request $request, Round $round) {
41 $this->authorize('setSeed', $round);
43 $validatedData = $request->validate([
44 'seed' => 'required|url',
47 $round->seed = $validatedData['seed'];
50 Protocol::roundSeedSet(
56 RoundChanged::dispatch($round);
58 $round->load('results');
60 return $round->toJson();