protected function createNestedQuery(Builder $querybuilder, stdClass $rule, $condition = null)
    {
        if ($condition === null) {
            $condition = $rule->condition;
        }

        $condition = $this->validateCondition($condition);

        return $querybuilder->whereNested(function ($query) use (&$rule, &$querybuilder, &$condition) {
            foreach ($rule->rules as $loopRule) {
                $function = 'makeQuery';

                if ($this->isNested($loopRule)) {
                    $function = 'createNestedQuery';
                }

                $querybuilder = $this->{$function}($query, $loopRule, $rule->condition);
            }

        }, $condition);
    }
protected function createNestedQuery(Builder $querybuilder, stdClass $rule, $condition = null)
    {
        if ($condition === null) {
            $condition = $rule->condition;
        }

        $condition = $this->validateCondition($condition);

        return $querybuilder->whereNested(function ($query) use (&$rule, &$querybuilder, &$condition) {
            foreach ($rule->rules as $loopRule) {
                $function = 'makeQuery';

                if ($this->isNested($loopRule)) {
                    $function = 'createNestedQuery';
                }

                $querybuilder = $this->{$function}($query, $loopRule, $rule->condition);
            }

        }, $condition);
    }
protected function createNestedQuery ( Builder $ querybuilder , stdClass $ rule , $ condition = null ) { if ( $ condition === null ) { $ condition = $ rule -> condition ; } $ condition = $ this -> validateCondition ( $ condition ) ; return $ querybuilder -> whereNested ( function ( $ query ) use ( & $ rule , & $ querybuilder , & $ condition ) { foreach ( $ rule -> rules as $ loopRule ) { $ function = 'makeQuery' ; if ( $ this -> isNested ( $ loopRule ) ) { $ function = 'createNestedQuery' ; } $ querybuilder = $ this -> { $ function } ( $ query , $ loopRule , $ rule -> condition ) ; } } , $ condition ) ; }
Create nested queries

When a rule is actually a group of rules, we want to build a nested query with the specified condition (AND/OR)

@param Builder $querybuilder
@param stdClass $rule
@param string|null $condition
@return Builder
Create nested queries