refactor: fix the update validation role to exclude the current provider
This commit is contained in:
parent
48d2c1a47e
commit
bc69ea2f95
@ -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.");
|
||||
}
|
||||
},
|
||||
],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user