From f279010a0c2768bb4dd4a04842ecf91db027ead3 Mon Sep 17 00:00:00 2001 From: Kevin McKee Date: Sat, 13 Feb 2021 16:15:13 -0600 Subject: [PATCH] wip --- README.md | 4 ++-- src/Commands/GenerateCommand.php | 3 +++ src/Stubs/migration.stub | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c305851..1f24b70 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,9 @@ public function up() Schema::create('post_tag', function (Blueprint $table) { $table->unsignedBigInteger('post_id'); $table->unsignedBigInteger('tag_id'); - $table->foreign('post_id')->references('id')->on('users') + $table->foreign('post_id')->references('id')->on('posts') ->onDelete('cascade'); - $table->foreign('tag_id')->references('id')->on('roles') + $table->foreign('tag_id')->references('id')->on('tags') ->onDelete('cascade'); }); } diff --git a/src/Commands/GenerateCommand.php b/src/Commands/GenerateCommand.php index 9588ca8..84fe5ad 100644 --- a/src/Commands/GenerateCommand.php +++ b/src/Commands/GenerateCommand.php @@ -55,6 +55,9 @@ public function handle() $newMigration = str_replace('|LOWERFIRST|', Str::snake($first), $newMigration); $newMigration = str_replace('|UPPERSECOND|', $second, $newMigration); $newMigration = str_replace('|LOWERSECOND|', Str::snake($second), $newMigration); + $newMigration = str_replace('|LOWERPLURALFIRST|', Str::snake(Str::plural($first)), $newMigration); + $newMigration = str_replace('|LOWERPLURALSECOND|', Str::snake(Str::plural($second)), $newMigration); + $this->files->put( base_path('database/migrations/' . now()->format('Y_m_d_His') . '_create_many_to_many_pivot_for_' diff --git a/src/Stubs/migration.stub b/src/Stubs/migration.stub index 323ea10..5bac4c1 100644 --- a/src/Stubs/migration.stub +++ b/src/Stubs/migration.stub @@ -16,9 +16,9 @@ class CreateManyToManyPivotFor|UPPERFIRST||UPPERSECOND| extends Migration Schema::create('|LOWERFIRST|_|LOWERSECOND|', function (Blueprint $table) { $table->unsignedBigInteger('|LOWERFIRST|_id'); $table->unsignedBigInteger('|LOWERSECOND|_id'); - $table->foreign('|LOWERFIRST|_id')->references('id')->on('users') + $table->foreign('|LOWERFIRST|_id')->references('id')->on('|LOWERPLURALFIRST|') ->onDelete('cascade'); - $table->foreign('|LOWERSECOND|_id')->references('id')->on('roles') + $table->foreign('|LOWERSECOND|_id')->references('id')->on('|LOWERPLURALSECOND|') ->onDelete('cascade'); }); }