From 4a3a80c1013b13e41a4985ff9ecaa886f3a2fffe Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sat, 26 Oct 2024 00:18:29 +0200 Subject: [PATCH] Add validation attributes to nami field --- modules/Nami/Components/SettingView.php | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/modules/Nami/Components/SettingView.php b/modules/Nami/Components/SettingView.php index 76e1b2f9..5abd4615 100644 --- a/modules/Nami/Components/SettingView.php +++ b/modules/Nami/Components/SettingView.php @@ -5,6 +5,7 @@ namespace Modules\Nami\Components; use App\Initialize\Actions\NamiLoginCheckAction; use App\Setting\NamiSettings; use Illuminate\Validation\ValidationException; +use Livewire\Attributes\Validate; use Livewire\Component; use Zoomyboy\LaravelNami\LoginException; @@ -12,18 +13,13 @@ class SettingView extends Component { public $settingClass = NamiSettings::class; - public string $password = ''; - public string $mglnr = ''; - public string $default_group_id = ''; - public function rules(): array - { - return [ - 'password' => 'required|string', - 'default_group_id' => 'required', - 'mglnr' => 'required', - ]; - } + #[Validate('required|string')] + public string $password = ''; + #[Validate('required|string')] + public string $mglnr = ''; + #[Validate('required|string')] + public string $default_group_id = ''; public function mount(): void { @@ -35,10 +31,7 @@ class SettingView extends Component { $validated = $this->validate(); try { - NamiLoginCheckAction::run([ - 'mglnr' => $this->mglnr, - 'password' => $this->password, - ]); + NamiLoginCheckAction::run($this->only(['mglnr', 'password'])); app(NamiSettings::class)->fill($validated)->save(); $this->dispatch('success', 'Einstellungen gespeichert.'); } catch (LoginException $e) {