Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Extend eloquent higher order proxy properties #41449

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
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
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