From bc69ea2f957948940e4d0fb3b66d8d3be8beb2b9 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 15 May 2026 09:35:26 +0000 Subject: [PATCH] refactor: fix the update validation role to exclude the current provider --- .../Forms/StoreConnectionProviderForm.php | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Livewire/Forms/StoreConnectionProviderForm.php b/app/Livewire/Forms/StoreConnectionProviderForm.php index 148e95b..0e2b8a2 100644 --- a/app/Livewire/Forms/StoreConnectionProviderForm.php +++ b/app/Livewire/Forms/StoreConnectionProviderForm.php @@ -14,9 +14,12 @@ class StoreConnectionProviderForm extends Form { public string $name = ''; - public function set(ConnectionProviderData $data): void + public ?int $connectionProviderId = null; + + public function set(ConnectionProviderData $provider): void { - $this->name = $data->name; + $this->connectionProviderId = $provider->id; + $this->name = $provider->name; } public function rules(): array @@ -27,17 +30,18 @@ public function rules(): array 'string', 'min:3', 'max:255', - // Custom Closure to check the generated slug function (string $attribute, mixed $value, Closure $fail): void { $slug = Str::slug($value); - // Check if the slug already exists in your database table - $exists = ConnectionProvider::query() - ->where('slug', $slug) - ->exists(); + $query = ConnectionProvider::query() + ->where('slug', $slug); - if ($exists) { - $fail("The name '{$value}' is already taken. Please choose a different name."); + if ($this->connectionProviderId) { + $query->where('id', '!=', $this->connectionProviderId); + } + + if ($query->exists()) { + $fail("The name '{$value}' is already taken."); } }, ],