diff --git a/resources/stubs/component.stub b/resources/stubs/component.stub index 01f96fd0b7..1cfd7daf6e 100644 --- a/resources/stubs/component.stub +++ b/resources/stubs/component.stub @@ -5,7 +5,7 @@ namespace Filament\Http\Livewire; use Filament\Support\Livewire\FormComponent; use Filament\Support\Fields\ArrayField; use Filament\Support\Fields\Field; -use Filament\Contracts\Dummy as DummyContract; +// use Filament\Contracts\Dummy as DummyContract; class DummyComponent extends FormComponent { @@ -23,13 +23,13 @@ class DummyComponent extends FormComponent public function success() { - $DummyClass = app(DummyContract::class); - $DummyClass::create($this->form_data); + // $DummyClass = app(DummyContract::class); + // $DummyClass::create($this->form_data); } public function saveAndGoBackResponse() { - return redirect()->route('filament.admin.DummyRoute.index'); + return redirect('/'); // redirect()->route('filament.admin.dashboard'); } public function render() diff --git a/src/Commands/MakeForm.php b/src/Commands/MakeForm.php index 5c8a02b739..2e4eb16e06 100644 --- a/src/Commands/MakeForm.php +++ b/src/Commands/MakeForm.php @@ -10,24 +10,31 @@ use Filament; class MakeForm extends Command { - protected $signature = 'filament:form {name} {--model=Model}'; + protected $signature = 'filament:form {name} {--model=Model} {--package}'; protected $description = 'Make a new Filament Livewire form component.'; public function handle() { + $componentName = Str::studly($this->argument('name')); + $stub = File::get(__DIR__ . '/../../resources/stubs/component.stub'); - $stub = str_replace('DummyComponent', $this->argument('name'), $stub); + $stub = str_replace('DummyComponent', $componentName, $stub); $stub = str_replace('Contracts\Dummy', 'Contracts\\' . $this->option('model'), $stub); $stub = str_replace('DummyClass', lcFirst($this->option('model')).'Class', $stub); $stub = str_replace('DummyContract', $this->option('model').'Contract', $stub); $stub = str_replace('DummyRoute', Str::slug(Str::plural($this->option('model'))), $stub); - $stub = str_replace('DummyView', Str::kebab($this->argument('name')), $stub); + $stub = str_replace('DummyView', Str::kebab($componentName), $stub); + + if (!$this->option('package')) { + $stub = str_replace('namespace Filament', 'namespace App', $stub); + } - $path = __DIR__ . '/../Http/Livewire/' . $this->argument('name') . '.php'; + $formPath = $this->option('package') ? __DIR__ . '/../Http/Livewire/' : app_path('Http/Livewire/'); + $path = $formPath . $componentName . '.php'; - if (!File::exists($path) || $this->confirm($this->argument('name') . ' already exists. Overwrite it?')) { + if (!File::exists($path) || $this->confirm($componentName . ' already exists. Overwrite it?')) { File::put($path, $stub); - $this->info($this->argument('name') . ' was made!'); + $this->info($componentName . ' was created in '. $formPath); } } }