refactor: fix the update validation role to exclude the current provider

This commit is contained in:
= 2026-05-15 09:35:26 +00:00
parent 48d2c1a47e
commit bc69ea2f95

View File

@ -14,9 +14,12 @@ class StoreConnectionProviderForm extends Form
{ {
public string $name = ''; 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 public function rules(): array
@ -27,17 +30,18 @@ public function rules(): array
'string', 'string',
'min:3', 'min:3',
'max:255', 'max:255',
// Custom Closure to check the generated slug
function (string $attribute, mixed $value, Closure $fail): void { function (string $attribute, mixed $value, Closure $fail): void {
$slug = Str::slug($value); $slug = Str::slug($value);
// Check if the slug already exists in your database table $query = ConnectionProvider::query()
$exists = ConnectionProvider::query() ->where('slug', $slug);
->where('slug', $slug)
->exists();
if ($exists) { if ($this->connectionProviderId) {
$fail("The name '{$value}' is already taken. Please choose a different name."); $query->where('id', '!=', $this->connectionProviderId);
}
if ($query->exists()) {
$fail("The name '{$value}' is already taken.");
} }
}, },
], ],