Skip to content

[11.28.0] ->orWhere() behaviour changed with array input #53184

@Dmitrev

Description

@Dmitrev

Laravel Version

11.28.0

PHP Version

8.2.24

Database Driver & Version

No response

Description

I'm not sure if this was a bug and is now fixed, but either way it's a breaking change and thought it was worth creating an issue for.

The Query builder ->orWhere() command by default now combines statements using the OR rather than AND keywords

I found an closed PR that is related to this:
#53147

The following change broke the functionality:
https://github.com/laravel/framework/pull/53147/files#diff-2ed94a0ea151404a12f3c0d52ae9fb5742348578ec4a8ff79d079fa598ff145d

Perhaps this needed to be patch for Query builder as well? PR was only targeting Eloquent

I think the Query builder should probably have the same functionality of passing a boolean param to avoid having the functionality be inconsistent between the two.

There is a clear workaround in this case, which is to not use the array syntax and instead use the orWhere with a callback like this:

$query->orWhere(function(Builder $query) {
    $query->where(...)->where(...);
});

Steps To Reproduce

Run the following in tinker (should work on any clean install of Laravel):

DB::table('users')->orWhere([['id', '=', 1], ['id', '=', 2]])->toRawSql();

output Laravel 11.28.0:

= "select * from `users` where (`id` = 1 or `id` = 2)"

output Laravel 11.23.5 (notice the and instead of or)

= "select * from `users` where (`id` = 1 and `id` = 2)"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions