From d1e5b818dcfd81254c334a44a91b9ef17ac2a39d Mon Sep 17 00:00:00 2001 From: Jonas Staudenmeir Date: Wed, 25 Apr 2018 16:25:04 +0200 Subject: [PATCH] Ignore non-where bindings in nested where() constraints --- src/Illuminate/Database/Query/Builder.php | 2 +- tests/Database/DatabaseQueryBuilderTest.php | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Query/Builder.php b/src/Illuminate/Database/Query/Builder.php index bb0f40cffa21..6d312c9ac9e7 100755 --- a/src/Illuminate/Database/Query/Builder.php +++ b/src/Illuminate/Database/Query/Builder.php @@ -1289,7 +1289,7 @@ public function addNestedWhereQuery($query, $boolean = 'and') $this->wheres[] = compact('type', 'query', 'boolean'); - $this->addBinding($query->getBindings(), 'where'); + $this->addBinding($query->getRawBindings()['where'], 'where'); } return $this; diff --git a/tests/Database/DatabaseQueryBuilderTest.php b/tests/Database/DatabaseQueryBuilderTest.php index b4f6a36130e4..7a4839b7a388 100755 --- a/tests/Database/DatabaseQueryBuilderTest.php +++ b/tests/Database/DatabaseQueryBuilderTest.php @@ -980,6 +980,15 @@ public function testNestedWheres() $this->assertEquals([0 => 'foo', 1 => 'bar', 2 => 25], $builder->getBindings()); } + public function testNestedWhereBindings() + { + $builder = $this->getBuilder(); + $builder->where('email', '=', 'foo')->where(function ($q) { + $q->selectRaw('?', ['ignore'])->where('name', '=', 'bar'); + }); + $this->assertEquals([0 => 'foo', 1 => 'bar'], $builder->getBindings()); + } + public function testFullSubSelects() { $builder = $this->getBuilder();