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 'no_record' => $tournament->no_record,
27 'tournament_id' => $validatedData['tournament_id'],
36 RoundAdded::dispatch($round);
38 return $round->toJson();
41 public function setSeed(Request $request, Round $round) {
42 $this->authorize('setSeed', $round);
44 $validatedData = $request->validate([
45 'seed' => 'required|url',
48 $round->seed = $validatedData['seed'];
51 Protocol::roundSeedSet(
57 RoundChanged::dispatch($round);
59 $round->load('results');
61 return $round->toJson();
64 public function lock(Request $request, Round $round) {
65 $this->authorize('lock', $round);
67 $round->locked = true;
70 Protocol::roundLocked(
76 RoundChanged::dispatch($round);
78 $round->load('results');
80 return $round->toJson();
83 public function unlock(Request $request, Round $round) {
84 $this->authorize('unlock', $round);
86 $round->locked = false;
89 Protocol::roundUnlocked(
95 RoundChanged::dispatch($round);
97 $round->load('results');
99 return $round->toJson();