diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index f93b217f9bc7..365247f69f68 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1246,7 +1246,7 @@ protected function callScope(callable $scope, array $parameters = []) $originalWhereCount = is_null($query->wheres) ? 0 : count($query->wheres); - $result = $scope(...array_values($parameters)) ?? $this; + $result = $scope(...$parameters) ?? $this; if (count((array) $query->wheres) > $originalWhereCount) { $this->addNewWheresWithinGroup($query, $originalWhereCount); diff --git a/tests/Database/DatabaseEloquentBuilderTest.php b/tests/Database/DatabaseEloquentBuilderTest.php index fc22a94eb3f4..c22010595d93 100755 --- a/tests/Database/DatabaseEloquentBuilderTest.php +++ b/tests/Database/DatabaseEloquentBuilderTest.php @@ -832,6 +832,28 @@ public function testQueryScopes() $this->assertEquals($builder, $result); } + public function testQueryDynamicScopes() + { + $builder = $this->getBuilder(); + $builder->getQuery()->shouldReceive('from'); + $builder->getQuery()->shouldReceive('where')->once()->with('bar', 'foo'); + $builder->setModel($model = new EloquentBuilderTestDynamicScopeStub); + $result = $builder->dynamic('bar', 'foo'); + + $this->assertEquals($builder, $result); + } + + public function testQueryDynamicScopesNamed() + { + $builder = $this->getBuilder(); + $builder->getQuery()->shouldReceive('from'); + $builder->getQuery()->shouldReceive('where')->once()->with('foo', 'foo'); + $builder->setModel($model = new EloquentBuilderTestDynamicScopeStub); + $result = $builder->dynamic(bar: 'foo'); + + $this->assertEquals($builder, $result); + } + public function testNestedWhere() { $nestedQuery = m::mock(Builder::class); @@ -1939,6 +1961,14 @@ public function scopeApproved($query) } } +class EloquentBuilderTestDynamicScopeStub extends Model +{ + public function scopeDynamic($query, $foo = 'foo', $bar = 'bar') + { + $query->where($foo, $bar); + } +} + class EloquentBuilderTestHigherOrderWhereScopeStub extends Model { protected $table = 'table';