-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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.2] Cast unique validation exclude id to integer #14076
Conversation
I may be wrong, but if you add
|
@gpedro Would be great if it worked. But your suggested solution adds validation to the field, but does not cast the |
Thanks @GrahamCampbell for updating title, didn't knew to which branch (5.1 or 5.2 or 5.3) to tag this PR. |
What if someone is using UUIDs? |
@taylorotwell Well, if its really a string, then do not cast it and leave like it is? I've added conditional check to check if it is really an integer. Don't know how I can better check for casting. Would prefixing 'int:' the id might be better? e.g. |
I see thanks. |
Thanks @taylorotwell !!! |
@@ -1296,6 +1296,10 @@ protected function validateUnique($attribute, $value, $parameters) | |||
if (strtolower($id) == 'null') { | |||
$id = null; | |||
} | |||
|
|||
if (filter_var($id, FILTER_VALIDATE_INT) !== false) { | |||
$id = intval($id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be just (int) $id
. The two are the same, but this version is faster.
I have this quite complex validation rule and I use with mongodb:
unique:mongodb.responses,RY7bC4VBFdzFWBS3.age,123,visitor_id,survey_id,564ce591c560ca2c6a8b4568
The problem occurs that in MongoDB
where = 123
andwhere = '123'
are two different queries, where in MySQL there is no difference.Therefore I really need to cast ID attribute to integer to have it return the correct count for unique validation and I suppose that it can only be done from here.