diff --git a/resources/install/resources/views/layouts/app.blade.php.stub b/resources/install/resources/views/layouts/app.blade.php.stub index e01d929..495f629 100644 --- a/resources/install/resources/views/layouts/app.blade.php.stub +++ b/resources/install/resources/views/layouts/app.blade.php.stub @@ -15,7 +15,6 @@ @vite(['resources/js/app.js']) - @livewireStyles
@@ -79,13 +78,9 @@ @yield('content')
- @livewireScripts diff --git a/src/Commands/LivewireGeneratorCommand.php b/src/Commands/LivewireGeneratorCommand.php index edf91e4..813aef3 100644 --- a/src/Commands/LivewireGeneratorCommand.php +++ b/src/Commands/LivewireGeneratorCommand.php @@ -447,7 +447,7 @@ protected function modelReplacements() // Add quotes to the unwanted columns for fillable array_walk($filterColumns, function (&$value) { - $value = "\n\t\t\t'" . $value . "' => \$this-> " . $value; + $value = "\n\t\t\t\t'" . $value . "' => \$this-> " . $value; }); // CSV format @@ -475,7 +475,7 @@ protected function modelReplacements() // Add quotes to the unwanted columns for fillable */ array_walk($filterColumns, function (&$value) { - $value = "\n\t\t\t'" . $value . "' => \$this->faker->name,"; + $value = "\n\t\t\t'" . $value . "' => fake()->name(),"; }); // CSV format diff --git a/src/stubs/Livewire.stub b/src/stubs/Livewire.stub index 0033668..c0a2244 100644 --- a/src/stubs/Livewire.stub +++ b/src/stubs/Livewire.stub @@ -1,10 +1,11 @@ keyWord .'%'; - return view('livewire.{{modelNamePluralLowerCase}}.view', [ - '{{modelNamePluralLowerCase}}' => {{modelName}}::latest(){{search}} - ->paginate(10), - ]); - } + #[Computed] + public function filtered{{modelName}}s() + { + $keyWord = '%' . $this->keyWord . '%'; + return {{modelName}}::latest() + ->where(function ($query) use ($keyWord) { + $query{{search}}; + }) + ->paginate(10); + } + + public function render() + { + return view('livewire.{{modelNamePluralLowerCase}}.view', [ + '{{modelNamePluralLowerCase}}' => $this->filtered{{modelName}}s, + ]); + } public function cancel() { - $this->resetInput(); - } - - private function resetInput() - { {{resetfields}} + $this->reset(); } - public function store() + public function save() { $this->validate([{{rules}} ]); - {{modelName}}::create([ {{addfields}} - ]); - - $this->resetInput(); - $this->dispatchBrowserEvent('closeModal'); - session()->flash('message', '{{modelName}} Successfully created.'); - } + Flight::updateOrCreate( + ['id' => $this->selected_id], + [{{addfields}} + ] + ); - public function edit($id) - { - $record = {{modelName}}::findOrFail($id); - $this->selected_id = $id; {{editfields}} + $message = $this->selected_id ? '{{modelName}} Successfully updated.' : '{{modelName}} Successfully created.'; + $this->dispatch('closeModal'); + $this->reset(); + session()->flash('message', $message); } - public function update() + public function edit($id) { - $this->validate([{{rules}} - ]); - - if ($this->selected_id) { - $record = {{modelName}}::find($this->selected_id); - $record->update([ {{addfields}} - ]); - - $this->resetInput(); - $this->dispatchBrowserEvent('closeModal'); - session()->flash('message', '{{modelName}} Successfully updated.'); - } + $this->selected_id = $id; + $this->fill({{modelName}}::findOrFail($id)->toArray()); } public function destroy($id) diff --git a/src/stubs/views/modals.stub b/src/stubs/views/modals.stub index 034b599..7124548 100644 --- a/src/stubs/views/modals.stub +++ b/src/stubs/views/modals.stub @@ -1,40 +1,22 @@ - - \ No newline at end of file diff --git a/src/stubs/views/view.stub b/src/stubs/views/view.stub index 338bad1..4e9cf38 100644 --- a/src/stubs/views/view.stub +++ b/src/stubs/views/view.stub @@ -15,7 +15,7 @@
-
+
Add {{modelTitle}}s
@@ -39,7 +39,7 @@ Actions