diff --git a/app/Http/Livewire/Form/ModelForm.php b/app/Http/Livewire/Form/ModelForm.php new file mode 100644 index 0000000..491e235 --- /dev/null +++ b/app/Http/Livewire/Form/ModelForm.php @@ -0,0 +1,76 @@ +record), '\\'); + } + + public function updated($property, $value) + { + $this->validateOnly($property); + } + + /** + * Returns true if this record has not been stored in the database. + */ + public function isNew() : bool + { + return !$this->exist; + } + + /** + * Submit the form, create/update record. + */ + public function submit() + { + $this->validate(); + $this->record->save(); + + if ($this->isNew()) { + session()->flash('info', "{$this->getModelName()} was successfully created."); + return redirect()->route($this->redirect_route); + } + + $this->info("{$this->getModelName()} was successfully updated."); + } + + /** + * Render the setup page + */ + public function render() + { + $script = Str::lower($this->getModelName()); + + return view("form.$script") + ->layout('layouts.admin'); + } +}