fix: normalize values in unique field validation and wire ignoreEntityId#90
Merged
ManukMinasyan merged 7 commits into3.xfrom Feb 24, 2026
Merged
Conversation
…yId during edit Two bugs fixed: 1. UniqueCustomFieldValue compared raw input against stored (normalized) values. For link fields, entering "https://example.com" bypassed the uniqueness check against a stored "example.com" because the protocol was stripped by dehydrateStateUsing after validation ran. 2. AbstractFormComponent never passed the current record's ID to the uniqueness rule during edit, causing records to detect themselves as duplicates when saving unchanged unique values. Changes: - Add setValue()/getValue() to BaseFieldType for value normalization - Override setValue() in LinkFieldType to strip protocol and trim - UniqueCustomFieldValue now normalizes via field type before comparing - AbstractFormComponent passes record ID via closure to rules() - LinkComponent uses field type setValue() instead of inline regex - Add 17 Livewire integration tests for uniqueness validation
There was a problem hiding this comment.
Pull request overview
This PR fixes two bugs in custom field uniqueness validation: protocol normalization and edit-mode entity exclusion.
Changes:
- Added
setValue()/getValue()methods toBaseFieldTypefor value normalization, withLinkFieldTypeoverriding to strip protocols - Updated
UniqueCustomFieldValuerule to normalize values via field type before database comparison - Wired
ignoreEntityIdparameter throughAbstractFormComponentto exclude current record during edit validation
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Feature/Rules/UniqueCustomFieldValueTest.php | Comprehensive integration tests covering both protocol normalization and edit-mode bugs |
| src/Rules/UniqueCustomFieldValue.php | Refactored to normalize values via field type and extract query logic |
| src/Filament/Integration/Components/Forms/LinkComponent.php | Updated to use field type's setValue() instead of inline regex |
| src/Filament/Integration/Base/AbstractFormComponent.php | Changed rules() to closure to pass record ID at validation time |
| src/FieldTypeSystem/Definitions/LinkFieldType.php | Implements protocol-stripping normalization in setValue() |
| src/FieldTypeSystem/BaseFieldType.php | Added identity implementation of setValue()/getValue() methods |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
blank('0') returns false in Laravel, but the original code treated '0'
as an empty expression. Restore the explicit '0' check to avoid a
subtle behavior change in field visibility.
…closures
- Use getMorphClass() directly instead of two-step Relation::getMorphAlias()
fallback, matching codebase convention
- Collapse nested closures in LinkComponent dehydrateStateUsing to arrow
functions
- Restore '0' check in visibility guard (blank('0') is false in Laravel)
…ns and unique validation logic - Add explicit return types to closures and methods for better type safety - Normalize and improve consistency of `Closure` imports and doc annotations - Simplify conditional logic in AbstractFormComponent and cleanup orphaned value checks - Standardize string concatenation with `.` instead of interpolation for warnings/messages - Relocate and restore LinkFieldType `setValue` method for better class organization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
https://example.combypassed uniqueness check against storedexample.combecausedehydrateStateUsingstripped the protocol after validation ran. TheUniqueCustomFieldValuerule now normalizes values viaBaseFieldType::setValue()before comparing.AbstractFormComponentnever passed the current record's ID to the uniqueness rule, causing records to reject their own unchanged unique values during edit. Now passes$record->getKey()via a closure in->rules().Changes
setValue()/getValue()toBaseFieldType(identity by default)setValue()inLinkFieldTypeto striphttp:///https://and trimUniqueCustomFieldValuenormalizes via field type before DB comparisonAbstractFormComponentresolves record ID at validation time via closureLinkComponentusesfieldType->setValue()instead of inline regexTest plan