From 0a3c781525cd61c80d7b95f7f091b0ae2e67c388 Mon Sep 17 00:00:00 2001 From: Yaz Jallad Date: Fri, 12 Jul 2019 12:39:56 -0700 Subject: [PATCH 1/2] allow `whereNull` to accept array columns argument --- src/Illuminate/Database/Query/Builder.php | 8 ++++--- tests/Database/DatabaseQueryBuilderTest.php | 26 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 2ef4b815c0b9..9b53d468a151 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -996,16 +996,18 @@ public function whereIntegerNotInRaw($column, $values, $boolean = 'and') /** * Add a "where null" clause to the query. * - * @param string $column + * @param string|array $column * @param string $boolean * @param bool $not * @return $this */ - public function whereNull($column, $boolean = 'and', $not = false) + public function whereNull($columns, $boolean = 'and', $not = false) { $type = $not ? 'NotNull' : 'Null'; - $this->wheres[] = compact('type', 'column', 'boolean'); + foreach (Arr::wrap($columns) as $column) { + $this->wheres[] = compact('type', 'column', 'boolean'); + } return $this; } diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index 6aecfcd13de0..2998d5821e58 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -970,6 +970,19 @@ public function testBasicWhereNulls() $this->assertEquals([0 => 1], $builder->getBindings()); } + public function testArrayWhereNulls() + { + $builder = $this->getBuilder(); + $builder->select('*')->from('users')->whereNull(['id', 'expires_at']); + $this->assertEquals('select * from "users" where "id" is null and "expires_at" is null', $builder->toSql()); + $this->assertEquals([], $builder->getBindings()); + + $builder = $this->getBuilder(); + $builder->select('*')->from('users')->where('id', '=', 1)->orWhereNull(['id', 'expires_at']); + $this->assertEquals('select * from "users" where "id" = ? or "id" is null or "expires_at" is null', $builder->toSql()); + $this->assertEquals([0 => 1], $builder->getBindings()); + } + public function testBasicWhereNotNulls() { $builder = $this->getBuilder(); @@ -983,6 +996,19 @@ public function testBasicWhereNotNulls() $this->assertEquals([0 => 1], $builder->getBindings()); } + public function testArrayWhereNotNulls() + { + $builder = $this->getBuilder(); + $builder->select('*')->from('users')->whereNotNull(['id', 'expires_at']); + $this->assertEquals('select * from "users" where "id" is not null and "expires_at" is not null', $builder->toSql()); + $this->assertEquals([], $builder->getBindings()); + + $builder = $this->getBuilder(); + $builder->select('*')->from('users')->where('id', '>', 1)->orWhereNotNull(['id', 'expires_at']); + $this->assertEquals('select * from "users" where "id" > ? or "id" is not null or "expires_at" is not null', $builder->toSql()); + $this->assertEquals([0 => 1], $builder->getBindings()); + } + public function testGroupBys() { $builder = $this->getBuilder(); From af1bf7fd1fb408ef25004dcd04402d4cc219c9d3 Mon Sep 17 00:00:00 2001 From: Yaz Jallad Date: Fri, 12 Jul 2019 12:51:55 -0700 Subject: [PATCH 2/2] update param name in docblock --- src/Illuminate/Database/Query/Builder.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index 9b53d468a151..e63b940c98b8 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -996,7 +996,7 @@ public function whereIntegerNotInRaw($column, $values, $boolean = 'and') /** * Add a "where null" clause to the query. * - * @param string|array $column + * @param string|array $columns * @param string $boolean * @param bool $not * @return $this