From 26f120549ad389ff64f7416c6f5414a438db4a4d Mon Sep 17 00:00:00 2001 From: Charalampos Raftopoulos Date: Mon, 11 Dec 2023 13:34:12 +0200 Subject: [PATCH] fix migration generation issue (#58) --- src/Migrations/MigrationCreator.php | 53 +++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/src/Migrations/MigrationCreator.php b/src/Migrations/MigrationCreator.php index a2fed9cb..6dae5fd8 100644 --- a/src/Migrations/MigrationCreator.php +++ b/src/Migrations/MigrationCreator.php @@ -6,6 +6,53 @@ class MigrationCreator extends IlluminateMigrationCreator { + /** + * Create a new migration at the given path. + * + * @param string $name + * @param string $path + * @param string|null $table + * @param bool $create + * @return string + * + * @throws \Exception + */ + public function create($name, $path, $table = null, $create = false) + { + $this->ensureMigrationDoesntAlreadyExist($name, $path); + + // First we will get the stub file for the migration, which serves as a type + // of template for the migration. Once we have those we will populate the + // various place-holders, save the file, and run the post create event. + $stub = $this->getStub($table, $create); + + $path = $this->getPath($name, $path); + + $this->files->ensureDirectoryExists(dirname($path)); + + if ($table === null) { + $table = $name; + } + + if ($table !== null) { + $stub = $this->populateStub($stub, $table); + } else { + $stub = $this->populateStub($stub, $name); + } + + + $this->files->put( + $path, $stub + ); + + // Next, we will fire any hooks that are supposed to fire after a migration is + // created. Once that is done we'll be ready to return the full path to the + // migration file so it can be used however it's needed by the developer. + $this->firePostCreateHooks($table, $path); + + return $path; + } + /** * Populate the place-holders in the migration stub. * @@ -15,18 +62,18 @@ class MigrationCreator extends IlluminateMigrationCreator * * @return string */ - protected function populateStub($stub, $label) + protected function populateStub($stub, $table) { $stub = str_replace( ['DummyClass', '{{ class }}', '{{class}}'], - $this->getClassName($name), + $this->getClassName($table), $stub ); // Here we will replace the label place-holders with the label specified by // the developer, which is useful for quickly creating a labels creation // or update migration from the console instead of typing it manually. - if (!is_null($label)) { + if (!is_null($table)) { $stub = str_replace( ['DummyTable', '{{ table }}', '{{table}}'], $table,