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."); } }, ],