From 7eadfd7fa124a7a579f0c0dd7e59a18da31970c6 Mon Sep 17 00:00:00 2001 From: Milwad Date: Thu, 30 May 2024 16:10:57 +0330 Subject: [PATCH] fix namespace of factory --- .../Modules/MakeCrudModuleCommand.php | 26 +++++-------------- src/Stubs/module/factory.stub | 18 +++++++++++++ 2 files changed, 24 insertions(+), 20 deletions(-) create mode 100644 src/Stubs/module/factory.stub diff --git a/src/Commands/Modules/MakeCrudModuleCommand.php b/src/Commands/Modules/MakeCrudModuleCommand.php index ae05408..be0dca3 100644 --- a/src/Commands/Modules/MakeCrudModuleCommand.php +++ b/src/Commands/Modules/MakeCrudModuleCommand.php @@ -313,27 +313,13 @@ private function makeSeeder(string $name) */ private function makeFactory(string $name) { - $filename = $name.'Factory'; $factoryPath = config('laravel-crod.modules.factory_path', 'Database\Factories'); - $correctPath = LaravelCrodServiceFacade::changeBackSlashToSlash($factoryPath); - $this->callSilent('make:factory', [ - 'name' => $filename, - ]); - - try { - $filenameWithExt = "$filename.php"; - $concurrentDirectory = base_path($this->module_name_space."/$name/$correctPath"); - - if (!mkdir($concurrentDirectory) && !is_dir($concurrentDirectory)) { - throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory)); - } - rename( - database_path("factories/$filenameWithExt"), - base_path($this->module_name_space."/$name/$correctPath/$filenameWithExt") - ); - } catch (\Exception $e) { - $this->error($e->getMessage()); - } + $this->makeStubFile( + base_path($this->module_name_space."\\$name\\$factoryPath"), + $name, + 'Factory', + '/../Stubs/module/factory.stub' + ); } } diff --git a/src/Stubs/module/factory.stub b/src/Stubs/module/factory.stub new file mode 100644 index 0000000..ac8b7e3 --- /dev/null +++ b/src/Stubs/module/factory.stub @@ -0,0 +1,18 @@ +