]> git.localhorst.tv Git - alttp.git/commitdiff
autonumber rounds
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 16 Mar 2022 15:08:32 +0000 (16:08 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Wed, 16 Mar 2022 15:08:32 +0000 (16:08 +0100)
app/Http/Controllers/RoundController.php
app/Models/Round.php
database/migrations/2022_03_16_145613_add_round_number.php [new file with mode: 0644]
database/migrations/2022_03_16_150425_round_code_default.php [new file with mode: 0644]

index d884d544bb22f5bd728e5e2f24859ab81ea6647e..f7e70423f07a987689e03bc5ec15f69f64bc7da4 100644 (file)
@@ -19,7 +19,10 @@ class RoundController extends Controller
                $tournament = Tournament::findOrFail($validatedData['tournament_id']);
                $this->authorize('addRound', $tournament);
 
+               $tournament->loadMax('rounds', 'number');
+
                $round = Round::create([
+                       'number' => intval($tournament->rounds_max_number) + 1,
                        'tournament_id' => $validatedData['tournament_id'],
                ]);
 
index e93501079aa3ca183cac26ad7c455bff48422a67..927307c2a7d5dc151b0485a36343134b457f151a 100644 (file)
@@ -22,6 +22,7 @@ class Round extends Model
        ];
 
        protected $fillable = [
+               'number',
                'tournament_id',
        ];
 
diff --git a/database/migrations/2022_03_16_145613_add_round_number.php b/database/migrations/2022_03_16_145613_add_round_number.php
new file mode 100644 (file)
index 0000000..bc8827d
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+       /**
+        * Run the migrations.
+        *
+        * @return void
+        */
+       public function up()
+       {
+               Schema::table('rounds', function(Blueprint $table) {
+                       $table->integer('number')->nullable()->default(null);
+               });
+       }
+
+       /**
+        * Reverse the migrations.
+        *
+        * @return void
+        */
+       public function down()
+       {
+               Schema::table('rounds', function(Blueprint $table) {
+                       $table->dropColumn('number');
+               });
+       }
+};
diff --git a/database/migrations/2022_03_16_150425_round_code_default.php b/database/migrations/2022_03_16_150425_round_code_default.php
new file mode 100644 (file)
index 0000000..8554b0a
--- /dev/null
@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+       /**
+        * Run the migrations.
+        *
+        * @return void
+        */
+       public function up()
+       {
+               Schema::table('rounds', function(Blueprint $table) {
+                       $table->text('code')->nullable()->default(null)->change();
+               });
+       }
+
+       /**
+        * Reverse the migrations.
+        *
+        * @return void
+        */
+       public function down()
+       {
+               Schema::table('rounds', function(Blueprint $table) {
+                       $table->text('code')->change();
+               });
+       }
+};