cms
cms copied to clipboard
[5.x] Fix unique entry value validation for date fields
The UniqueEntryValue validation doesn't work with date fields. The query doesn't seem to work if $value is a carbon instance:
$existing = $query
->when(
is_array($value),
fn ($query) => $query->whereIn($attribute, $value),
fn ($query) => $query->where($attribute, $value)
)
->first();
~~In this PR I simply add toDateString() to $value if it is a Carbon instance.~~
EDIT: In this PR I added a check to handle Carbon values, both for single and range values. I also added matching tests.
Uh, I should cover the array case as well 🙈 Back to draft.
Maybe a test wouldn't harm either.
EDIT: mode: range handling added, plus tests ✔️
Can you clarify the original issue you were running into?
The existing validation logic seems to work for me without these changes, unless I'm using the range mode, which is broken without these changes.
Closing this for now. We'll happily reopen once you can respond.