diff --git a/app/Http/Livewire/Form/CharacterForm.php b/app/Http/Livewire/Form/CharacterForm.php new file mode 100644 index 0000000..136efa0 --- /dev/null +++ b/app/Http/Livewire/Form/CharacterForm.php @@ -0,0 +1,81 @@ +character = $character; + $this->exist = $character->exists; + } + + /** + * Validation rules + */ + protected function rules() + { + return [ + 'character.name' => 'required|string|min:3|max:14', + ]; + } + + public function updated($property, $value) + { + $this->validateOnly($property); + } + + /** + * Returns true if this card has not been stored in the database. + */ + public function isNew() : bool + { + return !$this->exist; + } + + /** + * Submit the form, create/update card. + */ + public function submit() + { + $this->validate(); + $this->character->save(); + + if ($this->isNew()) { + session()->flash('info', 'Character was successfully created.'); + return redirect()->route('admin.character.index'); + } + + $this->info('Character was successfully updated.'); + } + + /** + * Render the setup page + */ + public function render() + { + return view('form.character') + ->layout('layouts.admin'); + } +} diff --git a/resources/views/form/character.blade.php b/resources/views/form/character.blade.php new file mode 100644 index 0000000..bfbafdc --- /dev/null +++ b/resources/views/form/character.blade.php @@ -0,0 +1,17 @@ + +
+ + {{ __(($this->isNew() ? 'Create' : 'Edit') . ' character') }} + +
+ +
+ {{ __('Name') }} + +
+ + {{ __('Save') }} + {{ __('Back') }} +
+ +