diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index a701aeeb0dd9..51ba2638d8a6 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -1158,7 +1158,7 @@ public function scopes(array $scopes) } $builder = $builder->callScope( - 'scope'.ucfirst($scope), (array) $parameters + [$this->model, 'scope'.ucfirst($scope)], (array) $parameters ); } diff --git a/tests/Database/DatabaseEloquentModelTest.php b/tests/Database/DatabaseEloquentModelTest.php index c242a039cea0..b42bbf7bbc72 100755 --- a/tests/Database/DatabaseEloquentModelTest.php +++ b/tests/Database/DatabaseEloquentModelTest.php @@ -2,6 +2,7 @@ use Mockery as m; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Relations\Relation; class DatabaseEloquentModelTest extends PHPUnit_Framework_TestCase @@ -1348,6 +1349,22 @@ public function testStringIdTypePreserved() $this->assertEquals('string id', $model->id); } + public function testScopesMethod() + { + $model = new EloquentModelStub; + $this->addMockConnection($model); + + $scopes = [ + 'published', + 'category' => 'Laravel', + 'framework' => ['Laravel', '5.2'], + ]; + + $this->assertInstanceOf(Builder::class, $model->scopes($scopes)); + + $this->assertSame($scopes, $model->scopesCalled); + } + protected function addMockConnection($model) { $model->setConnectionResolver($resolver = m::mock('Illuminate\Database\ConnectionResolverInterface')); @@ -1371,6 +1388,7 @@ public function saved() class EloquentModelStub extends Model { public $connection; + public $scopesCalled = []; protected $table = 'stub'; protected $guarded = []; protected $morph_to_stub_type = 'EloquentModelSaveStub'; @@ -1429,6 +1447,21 @@ public function getAppendableAttribute() { return 'appended'; } + + public function scopePublished(Builder $builder) + { + $this->scopesCalled[] = 'published'; + } + + public function scopeCategory(Builder $builder, $category) + { + $this->scopesCalled['category'] = $category; + } + + public function scopeFramework(Builder $builder, $framework, $version) + { + $this->scopesCalled['framework'] = [$framework, $version]; + } } class EloquentModelCamelStub extends EloquentModelStub