From 79c9fbddc491ed3514f132aca077baad127013b6 Mon Sep 17 00:00:00 2001 From: Sam Maosa Date: Sat, 6 Apr 2024 19:43:46 +0300 Subject: [PATCH] Feature: Seeder Generation - Added a command to generate seeders in a module --- src/Commands/SeederMakeCommand.php | 30 ++++++++++++++++++++++++++++++ src/Module.php | 4 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/Commands/SeederMakeCommand.php diff --git a/src/Commands/SeederMakeCommand.php b/src/Commands/SeederMakeCommand.php new file mode 100644 index 0000000..487084a --- /dev/null +++ b/src/Commands/SeederMakeCommand.php @@ -0,0 +1,30 @@ +getModule()->makeNamespace('Database\\Seeders\\'); + } + + protected function getDefaultNamespace($rootNamespace): string + { + return $rootNamespace; + } + + protected function getPath($name): string + { + $name = str_replace('\\', '/', Str::replaceFirst($this->rootNamespace(), '', $name)); + return $this->getModule()->seedersPath($name.'.php'); + } +} diff --git a/src/Module.php b/src/Module.php index 08ed944..a0a0001 100644 --- a/src/Module.php +++ b/src/Module.php @@ -92,9 +92,9 @@ public function migrationsPath(string $path = '', bool $relative = false): strin return $this->databasePath('migrations'.DIRECTORY_SEPARATOR.trim($path, DIRECTORY_SEPARATOR), relative: $relative); } - public function seedsPath(string $path = '', bool $relative = false): string + public function seedersPath(string $path = '', bool $relative = false): string { - return $this->databasePath('seeds'.DIRECTORY_SEPARATOR.trim($path, DIRECTORY_SEPARATOR), relative: $relative); + return $this->databasePath('seeders'.DIRECTORY_SEPARATOR.trim($path, DIRECTORY_SEPARATOR), relative: $relative); } public function factoriesPath(string $path = '', bool $relative = false): string