diff --git a/src/Commands/MakeComponent.php b/src/Commands/MakeComponent.php index 46c32edb..860b5d38 100644 --- a/src/Commands/MakeComponent.php +++ b/src/Commands/MakeComponent.php @@ -5,6 +5,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\File; use Illuminate\Support\Str; +use Livewire\Features\SupportConsoleCommands\Commands\ComponentParser; use Statamic\Console\RunsInPlease; use Statamic\Facades\Form; @@ -36,18 +37,22 @@ public function handle(): void options: $forms->mapWithKeys(fn ($form) => [$form->handle() => $form->title()]), ); + $classNamespace = config('livewire.class_namespace'); $className = Str::of($name)->endsWith('Form') ? $name : Str::of($name)->append('Form')->studly(); + $classPath = ComponentParser::generatePathFromNamespace($classNamespace).collect()->push("{$className}.php")->implode('/'); $stub = File::get(__DIR__.'/form.stub'); - $stub = str_replace('[className]', $className, $stub); - - $path = app_path("Livewire/{$className}.php"); + $stub = preg_replace( + ['/\[namespace\]/', '/\[class\]/'], + [$classNamespace, $className], + $stub + ); - if (! File::exists($path) || confirm(label: 'A component with this name already exists. Do you want to overwrite it?', default: false)) { - File::ensureDirectoryExists(app_path('Livewire')); - File::put($path, $stub); - info("The component was successfully created: {$this->getRelativePath($path)}"); + if (! File::exists($classPath) || confirm(label: 'A component with this name already exists. Do you want to overwrite it?', default: false)) { + File::ensureDirectoryExists(dirname($classPath)); + File::put($classPath, $stub); + info("The component was successfully created: {$this->getRelativePath($classPath)}"); } } diff --git a/src/Commands/form.stub b/src/Commands/form.stub index 77eff745..5c8fad9a 100644 --- a/src/Commands/form.stub +++ b/src/Commands/form.stub @@ -1,13 +1,13 @@