Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit 9a8813f

Browse files
committed
PHPORM-67 Accept operators prefixed by $ in Query\Builder::orWhere
1 parent 52c0ea3 commit 9a8813f

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
1111
- Throw an exception when `Query\Builder::orderBy()` is used with invalid direction [#7](https://github.com/GromNaN/laravel-mongodb-private/pull/7) by [@GromNaN](https://github.com/GromNaN).
1212
- Throw an exception when `Query\Builder::push()` is used incorrectly [#5](https://github.com/GromNaN/laravel-mongodb-private/pull/5) by [@GromNaN](https://github.com/GromNaN).
1313
- Remove public property `Query\Builder::$paginating` [#15](https://github.com/GromNaN/laravel-mongodb-private/pull/15) by [@GromNaN](https://github.com/GromNaN).
14+
- Accept operators prefixed by `$` in `Query\Builder::orWhere` [#15](https://github.com/GromNaN/laravel-mongodb-private/pull/15) by [@GromNaN](https://github.com/GromNaN).
1415

1516
## [3.9.2] - 2022-09-01
1617

src/Query/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -915,10 +915,10 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
915915
$params = func_get_args();
916916

917917
// Remove the leading $ from operators.
918-
if (func_num_args() == 3) {
918+
if (func_num_args() >= 3) {
919919
$operator = &$params[1];
920920

921-
if (Str::startsWith($operator, '$')) {
921+
if (is_string($operator) && str_starts_with($operator, '$')) {
922922
$operator = substr($operator, 1);
923923
}
924924
}

tests/Query/BuilderTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,19 @@ public static function provideQueryBuilderToMql(): iterable
7676
fn (Builder $builder) => $builder->limit(10)->offset(5)->select('foo', 'bar'),
7777
];
7878

79+
yield 'where accepts $ in operators' => [
80+
['find' => [
81+
['$or' => [
82+
['foo' => ['$type' => 2]],
83+
['foo' => ['$type' => 4]],
84+
]],
85+
[], // options
86+
]],
87+
fn (Builder $builder) => $builder
88+
->where('foo', '$type', 2)
89+
->orWhere('foo', '$type', 4),
90+
];
91+
7992
/** @see DatabaseQueryBuilderTest::testBasicWhereNot() */
8093
yield 'whereNot (multiple)' => [
8194
['find' => [

0 commit comments

Comments
 (0)