Skip to content

[7.x] Use valid methods when array value given for Query Builder where method#31323

Closed
mnabialek wants to merge 2 commits intolaravel:masterfrom
mnabialek:7.x-builder-where-array
Closed

[7.x] Use valid methods when array value given for Query Builder where method#31323
mnabialek wants to merge 2 commits intolaravel:masterfrom
mnabialek:7.x-builder-where-array

Conversation

@mnabialek
Copy link
Copy Markdown
Contributor

It seems at the moment Query Builder silently chooses only 1st value from array when array value given. There is no exception thrown so this could lead to potential risky situations when code doesn't behave as it should if by mistake you pass array to where method.

For example at the moment when you use code like this:

User::where('id', [5,2])->get();
User::where('id', '<>', [5,2])->get();

builder will generate queries like those:

select * from `users` where `id` = 5;
select * from `users` where `id` <> 5;

If this PR were accepted in case of developer error using such code, Builder would automatically fallback to whereIn and whereNotIn methods when possible.

I believe this change could potentially affect existing applications so it's better to target it to 7.x instead of 6.x

@taylorotwell
Copy link
Copy Markdown
Member

We already have a whereIn method that should be used.

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.

2 participants