Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

/**
* @property-read HigherOrderBuilderProxy $orWhere
* @property-read HigherOrderBuilderProxy $whereNot
* @property-read HigherOrderBuilderProxy $orWhereNot
*
* @mixin \Illuminate\Database\Query\Builder
*/
Expand Down Expand Up @@ -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);
}

Expand Down
32 changes: 32 additions & 0 deletions tests/Database/DatabaseEloquentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down