diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 830f54f860f7..f93b217f9bc7 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -22,6 +22,8 @@ /** * @property-read HigherOrderBuilderProxy $orWhere + * @property-read HigherOrderBuilderProxy $whereNot + * @property-read HigherOrderBuilderProxy $orWhereNot * * @mixin \Illuminate\Database\Query\Builder */ @@ -1655,7 +1657,7 @@ public static function hasGlobalMacro($name) */ public function __get($key) { - if ($key === 'orWhere') { + if (in_array($key, ['orWhere', 'whereNot', 'orWhereNot'])) { return new HigherOrderBuilderProxy($this, $key); } diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index 7c67368689e1..fc22a94eb3f4 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -956,6 +956,38 @@ public function testRealQueryChainedHigherOrderOrWhereScopes() $this->assertSame('select * from "table" where "one" = ? or ("two" = ?) or ("three" = ?)', $query->toSql()); } + public function testRealQueryHigherOrderWhereNotScopes() + { + $model = new EloquentBuilderTestHigherOrderWhereScopeStub; + $this->mockConnectionForModel($model, 'SQLite'); + $query = $model->newQuery()->one()->whereNot->two(); + $this->assertSame('select * from "table" where "one" = ? and not ("two" = ?)', $query->toSql()); + } + + public function testRealQueryChainedHigherOrderWhereNotScopes() + { + $model = new EloquentBuilderTestHigherOrderWhereScopeStub; + $this->mockConnectionForModel($model, 'SQLite'); + $query = $model->newQuery()->one()->whereNot->two()->whereNot->three(); + $this->assertSame('select * from "table" where "one" = ? and not ("two" = ?) and not ("three" = ?)', $query->toSql()); + } + + public function testRealQueryHigherOrderOrWhereNotScopes() + { + $model = new EloquentBuilderTestHigherOrderWhereScopeStub; + $this->mockConnectionForModel($model, 'SQLite'); + $query = $model->newQuery()->one()->orWhereNot->two(); + $this->assertSame('select * from "table" where "one" = ? or not ("two" = ?)', $query->toSql()); + } + + public function testRealQueryChainedHigherOrderOrWhereNotScopes() + { + $model = new EloquentBuilderTestHigherOrderWhereScopeStub; + $this->mockConnectionForModel($model, 'SQLite'); + $query = $model->newQuery()->one()->orWhereNot->two()->orWhereNot->three(); + $this->assertSame('select * from "table" where "one" = ? or not ("two" = ?) or not ("three" = ?)', $query->toSql()); + } + public function testSimpleWhere() { $builder = $this->getBuilder();