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 'game' => $tournament->game,
26 'number' => intval($tournament->rounds_max_number) + 1,
27 'no_record' => $tournament->no_record,
28 'tournament_id' => $validatedData['tournament_id'],
37 RoundAdded::dispatch($round);
39 return $round->toJson();
42 public function update(Request $request, Round $round) {
43 $this->authorize('update', $round);
45 $validatedData = $request->validate([
50 $round->seed = $validatedData['seed'];
51 $round->title = $validatedData['title'];
54 Protocol::roundEdited(
60 RoundChanged::dispatch($round);
62 $round->load(['results', 'results.user']);
64 return $round->toJson();
67 public function setSeed(Request $request, Round $round) {
68 $this->authorize('setSeed', $round);
70 $validatedData = $request->validate([
71 'seed' => 'required|url',
74 $round->seed = $validatedData['seed'];
77 Protocol::roundSeedSet(
83 RoundChanged::dispatch($round);
85 $round->load(['results', 'results.user']);
87 return $round->toJson();
90 public function lock(Request $request, Round $round) {
91 $this->authorize('lock', $round);
93 $round->locked = true;
96 Protocol::roundLocked(
102 RoundChanged::dispatch($round);
104 $round->load(['results', 'results.user']);
106 return $round->toJson();
109 public function unlock(Request $request, Round $round) {
110 $this->authorize('unlock', $round);
112 $round->locked = false;
115 Protocol::roundUnlocked(
121 RoundChanged::dispatch($round);
123 $round->load(['results', 'results.user']);
125 return $round->toJson();