form && $this->form->slug === $value) { return; } if (!preg_match('/^[a-z0-9]+(?:-[a-z0-9]+)*$/', $value)) { $fail('The custom slug can only contain lowercase letters, numbers, and hyphens.'); return; } // Check if the slug is unique, excluding current form $query = Form::where('slug', $value); if ($this->form) { $query->where('id', '!=', $this->form->id); } if ($query->exists()) { $fail('This slug is already in use. Please choose another one.'); return; } } }