cms icon indicating copy to clipboard operation
cms copied to clipboard

[5.x] Fix unique entry value validation for date fields

Open simonerd opened this issue 8 months ago • 2 comments

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.

simonerd avatar Mar 13 '25 10:03 simonerd

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 ✔️

simonerd avatar Mar 13 '25 10:03 simonerd

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.

duncanmcclean avatar May 22 '25 11:05 duncanmcclean

Closing this for now. We'll happily reopen once you can respond.

jasonvarga avatar Oct 15 '25 20:10 jasonvarga