Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] fix unique entry value validation for date fields #11569

Open
wants to merge 4 commits into
base: 5.x
Choose a base branch
from

Conversation

simonerd
Copy link
Contributor

@simonerd simonerd commented Mar 13, 2025

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 simonerd marked this pull request as draft March 13, 2025 10:16
@simonerd
Copy link
Contributor Author

simonerd commented Mar 13, 2025

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 simonerd marked this pull request as ready for review March 13, 2025 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant