diff --git a/src/Builder.php b/src/Builder.php index 8255c4b3..b035c958 100644 --- a/src/Builder.php +++ b/src/Builder.php @@ -102,9 +102,13 @@ public function whereBetween($field, array $values): self */ public function whereIn($field, array $values): self { - $wheres = array_map(function ($value) use ($field) { - return "$field={$this->transform($value)}"; - }, array_values($values)); + if(! empty($values)) { + $wheres = array_map(function ($value) use ($field) { + return "$field={$this->transform($value)}"; + }, array_values($values)); + } else { + $wheres = ['0 = 1']; + } $this->wheres[] = $wheres; diff --git a/tests/Features/WhereQueriesTest.php b/tests/Features/WhereQueriesTest.php index 38432e13..ee6252f4 100644 --- a/tests/Features/WhereQueriesTest.php +++ b/tests/Features/WhereQueriesTest.php @@ -89,6 +89,17 @@ public function testWhereIn(): void User::search('foo')->whereIn('id', [1, 2, 3, 4])->get(); } + public function testWhereInEmptyArray(): void + { + $this->mockIndex(User::class)->shouldReceive('search')->once()->with('foo', [ + 'numericFilters' => [ + ['0 = 1'], + ], + ])->andReturn(['hits' => []]); + + User::search('foo')->whereIn('id', [])->get(); + } + public function testMultipleWheres(): void { $this->mockIndex(User::class)->shouldReceive('search')->once()->with('foo', [