From: Daniel Karbach Date: Wed, 16 Mar 2022 15:08:32 +0000 (+0100) Subject: autonumber rounds X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=8b95f300549d865815d1a5b981844d1296898111;p=alttp.git autonumber rounds --- diff --git a/app/Http/Controllers/RoundController.php b/app/Http/Controllers/RoundController.php index d884d54..f7e7042 100644 --- a/app/Http/Controllers/RoundController.php +++ b/app/Http/Controllers/RoundController.php @@ -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'], ]); diff --git a/app/Models/Round.php b/app/Models/Round.php index e935010..927307c 100644 --- a/app/Models/Round.php +++ b/app/Models/Round.php @@ -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 index 0000000..bc8827d --- /dev/null +++ b/database/migrations/2022_03_16_145613_add_round_number.php @@ -0,0 +1,32 @@ +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 index 0000000..8554b0a --- /dev/null +++ b/database/migrations/2022_03_16_150425_round_code_default.php @@ -0,0 +1,32 @@ +text('code')->nullable()->default(null)->change(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('rounds', function(Blueprint $table) { + $table->text('code')->change(); + }); + } +};