Skip to content

Commit

Permalink
Don't bind macro when it is not a Closure (#21980)
Browse files Browse the repository at this point in the history
  • Loading branch information
alepeino authored and taylorotwell committed Nov 6, 2017
1 parent 66df916 commit a570041
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1254,12 +1254,12 @@ public function __call($method, $parameters)
return $this->localMacros[$method](...$parameters);
}

if (isset(static::$macros[$method]) and static::$macros[$method] instanceof Closure) {
return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters);
}

if (isset(static::$macros[$method])) {
return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters);
if (static::$macros[$method] instanceof Closure) {
return call_user_func_array(static::$macros[$method]->bindTo($this, static::class), $parameters);
}

return call_user_func_array(static::$macros[$method], $parameters);
}

if (method_exists($this->model, $scope = 'scope'.ucfirst($method))) {
Expand Down
7 changes: 6 additions & 1 deletion tests/Database/DatabaseEloquentBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,12 @@ public function testGlobalMacrosAreCalledOnBuilder()
return $bar;
});

$this->assertEquals($this->getBuilder()->foo('bar'), 'bar');
Builder::macro('bam', [Builder::class, 'getQuery']);

$builder = $this->getBuilder();

$this->assertEquals($builder->foo('bar'), 'bar');
$this->assertEquals($builder->bam(), $builder->getQuery());
}

public function testGetModelsProperlyHydratesModels()
Expand Down

0 comments on commit a570041

Please sign in to comment.