protected function callScope(callable $scope, $parameters = [])
{
array_unshift($parameters, $this);
$query = $this->getQuery();
// We will keep track of how many wheres are on the query before running the
// scope so that we can properly group the added scope constraints in the
// query as their own isolated nested where statement and avoid issues.
$originalWhereCount = count($query->wheres);
$result = call_user_func_array($scope, $parameters) ?: $this;
if ($this->shouldNestWheresForScope($query, $originalWhereCount)) {
$this->nestWheresForScope($query, $originalWhereCount);
}
return $result;
}