From 8b95f300549d865815d1a5b981844d1296898111 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Wed, 16 Mar 2022 16:08:32 +0100 Subject: [PATCH] autonumber rounds --- app/Http/Controllers/RoundController.php | 3 ++ app/Models/Round.php | 1 + .../2022_03_16_145613_add_round_number.php | 32 +++++++++++++++++++ .../2022_03_16_150425_round_code_default.php | 32 +++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 database/migrations/2022_03_16_145613_add_round_number.php create mode 100644 database/migrations/2022_03_16_150425_round_code_default.php 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(); + }); + } +}; -- 2.39.2