Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jan 28, 2022
1 parent 326b85a commit c86c992
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 45 deletions.
64 changes: 34 additions & 30 deletions Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1550,33 +1550,6 @@ public function addNestedWhereQuery($query, $boolean = 'and')
return $this;
}

public function havingNested(Closure $callback, $boolean = 'and')
{
call_user_func($callback, $query = $this->forNestedWhere());

return $this->addNestedHavingQuery($query, $boolean);
}

/**
* Add another query builder as a nested where to the query builder.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $boolean
* @return $this
*/
public function addNestedHavingQuery($query, $boolean = 'and')
{
if (count($query->havings)) {
$type = 'Nested';

$this->havings[] = compact('type', 'query', 'boolean');

$this->addBinding($query->getRawBindings()['having'], 'having');
}

return $this;
}

/**
* Add a full sub-select to the query.
*
Expand Down Expand Up @@ -1968,9 +1941,6 @@ public function having($column, $operator = null, $value = null, $boolean = 'and
$value, $operator, func_num_args() === 2
);

// If the columns is actually a Closure instance, we will assume the developer
// wants to begin a nested having statement which is wrapped in parenthesis.
// We'll add that Closure to the query then return back out immediately.
if ($column instanceof Closure && is_null($operator)) {
return $this->havingNested($column, $boolean);
}
Expand Down Expand Up @@ -2012,6 +1982,40 @@ public function orHaving($column, $operator = null, $value = null)
return $this->having($column, $operator, $value, 'or');
}

/**
* Add a nested having statement to the query.
*
* @param \Closure $callback
* @param string $boolean
* @return $this
*/
public function havingNested(Closure $callback, $boolean = 'and')
{
call_user_func($callback, $query = $this->forNestedWhere());

return $this->addNestedHavingQuery($query, $boolean);
}

/**
* Add another query builder as a nested having to the query builder.
*
* @param \Illuminate\Database\Query\Builder $query
* @param string $boolean
* @return $this
*/
public function addNestedHavingQuery($query, $boolean = 'and')
{
if (count($query->havings)) {
$type = 'Nested';

$this->havings[] = compact('type', 'query', 'boolean');

$this->addBinding($query->getRawBindings()['having'], 'having');
}

return $this;
}

/**
* Add a "having null" clause to the query.
*
Expand Down
28 changes: 13 additions & 15 deletions Query/Grammars/Grammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -688,11 +688,9 @@ protected function compileGroups(Builder $query, $groups)
*/
protected function compileHavings(Builder $query)
{
$sql = collect($query->havings)->map(function ($having) {
return 'having '.$this->removeLeadingBoolean(collect($query->havings)->map(function ($having) {
return $having['boolean'].' '.$this->compileHaving($having);
})->implode(' ');

return 'having '.$this->removeLeadingBoolean($sql);
})->implode(' '));
}

/**
Expand Down Expand Up @@ -724,17 +722,6 @@ protected function compileHaving(array $having)
return $this->compileBasicHaving($having);
}

/**
* Compile a nested having clause.
*
* @param array $having
* @return string
*/
protected function compileNestedHavings($having)
{
return '('.substr($this->compileHavings($having['query']), 7).')';
}

/**
* Compile a basic having clause.
*
Expand Down Expand Up @@ -810,6 +797,17 @@ protected function compileHavingBit($having)
return '('.$column.' '.$having['operator'].' '.$parameter.') != 0';
}

/**
* Compile a nested having clause.
*
* @param array $having
* @return string
*/
protected function compileNestedHavings($having)
{
return '('.substr($this->compileHavings($having['query']), 7).')';
}

/**
* Compile the "order by" portions of the query.
*
Expand Down

0 comments on commit c86c992

Please sign in to comment.