Permalink
Browse files

Return value from scope if one given.

  • Loading branch information...
taylorotwell committed Oct 31, 2013
1 parent d0fca18 commit 23adaa4068ad91fd934b58b6f60cef06135a76e3
Showing with 25 additions and 3 deletions.
  1. +25 −3 src/Illuminate/Database/Eloquent/Builder.php
@@ -687,6 +687,20 @@ protected function parseNested($name, $results)
return $results;
}
/**
* Call the given model scope on the underlying model.
*
* @param string $scope
* @param array $parameters
* @return \Illuminate\Database\Query\Builder
*/
protected function callScope($scope, $parameters)
{
array_unshift($parameters, $this);
return call_user_func_array(array($this->model, $scope), $parameters) ?: $this;
}
/**
* Get the underlying query builder instance.
*
@@ -765,9 +779,7 @@ public function __call($method, $parameters)
{
if (method_exists($this->model, $scope = 'scope'.ucfirst($method)))
{
array_unshift($parameters, $this);
call_user_func_array(array($this->model, $scope), $parameters);
return $this->callScope($scope, $parameters);
}
else
{
@@ -777,4 +789,14 @@ public function __call($method, $parameters)
return in_array($method, $this->passthru) ? $result : $this;
}
/**
* Force a clone of the underlying query builder when cloning.
*
* @return void
*/
public function __clone()
{
$this->query = clone $this->query;
}
}

0 comments on commit 23adaa4

Please sign in to comment.