diff --git a/src/Illuminate/Database/Console/Factories/FactoryMakeCommand.php b/src/Illuminate/Database/Console/Factories/FactoryMakeCommand.php index ac97ae80ecdd..aac32d84cf11 100644 --- a/src/Illuminate/Database/Console/Factories/FactoryMakeCommand.php +++ b/src/Illuminate/Database/Console/Factories/FactoryMakeCommand.php @@ -66,7 +66,14 @@ protected function buildClass($name) $model = class_basename($namespaceModel); + if (Str::startsWith($namespaceModel, 'App\\Models')) { + $namespace = Str::beforeLast('Database\\Factories\\'.Str::after($namespaceModel, 'App\\Models\\'), '\\'); + } else { + $namespace = 'Database\\Factories'; + } + $replace = [ + '{{ factoryNamespace }}' => $namespace, 'NamespacedDummyModel' => $namespaceModel, '{{ namespacedModel }}' => $namespaceModel, '{{namespacedModel}}' => $namespaceModel, @@ -88,13 +95,11 @@ protected function buildClass($name) */ protected function getPath($name) { - $name = str_replace( - ['\\', '/'], '', $this->argument('name') - ); + $name = Str::replaceFirst('App\\', '', $name); - $name = Str::finish($name, 'Factory'); + $name = Str::finish($this->argument('name'), 'Factory'); - return $this->laravel->databasePath()."/factories/{$name}.php"; + return $this->laravel->databasePath().'/factories/'.str_replace('\\', '/', $name).'.php'; } /** diff --git a/src/Illuminate/Database/Console/Factories/stubs/factory.stub b/src/Illuminate/Database/Console/Factories/stubs/factory.stub index bc895ed266b6..9734bc0e6258 100644 --- a/src/Illuminate/Database/Console/Factories/stubs/factory.stub +++ b/src/Illuminate/Database/Console/Factories/stubs/factory.stub @@ -1,6 +1,6 @@ argument('name'))); + $factory = Str::studly($this->argument('name')); $this->call('make:factory', [ 'name' => "{$factory}Factory",