Skip to content

Commit ff3c06e

Browse files
committed
Add aggregate method and DSL query support
1 parent 392c369 commit ff3c06e

2 files changed

Lines changed: 15 additions & 0 deletions

File tree

src/Eloquent/Docs/ModelDocs.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Query Builder Methods ---------------------------------
1616
*
1717
* @method static $this query()
18+
* @method static $this dslQuery()
1819
*-----------------------------------
1920
* @method static $this where($column, $operator = null, $value = null, $boolean = 'and', $options = [])
2021
* @method static $this whereNot($column, $operator = null, $value = null, $boolean = 'and', $options = [])
@@ -215,6 +216,7 @@
215216
* @method static int|array avg($columns)
216217
* @method static int|array average($columns)
217218
* @method static mixed agg(array $functions, $column)
219+
* @method static mixed aggregate(array $functions, $column)
218220
*-----------------------------------
219221
* @method static mixed boxplot($columns, $options = [])
220222
* @method static mixed cardinality($columns, $options = [])

src/Query/Builder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,8 +718,18 @@ public function avg($column, array $options = [])
718718
return $this->aggregate(__FUNCTION__, Arr::wrap($column), $options);
719719
}
720720

721+
/**
722+
* {@inheritdoc}
723+
*
724+
* @param string|array $function
725+
* @param Expression|string|array $columns
726+
*/
721727
public function aggregate($function, $columns = ['*'], $options = [])
722728
{
729+
if (is_array($function)) {
730+
return $this->aggregateMultiMetric($function, $columns, $options);
731+
}
732+
723733
return $this->aggregateMetric($function, $columns, $options);
724734
}
725735

@@ -1920,6 +1930,9 @@ protected function aggregateMultiMetric(array $functions, string|array $columns,
19201930
];
19211931
}
19221932
}
1933+
if ($this->asDsl) {
1934+
return $this->grammar->compileSelect($this);
1935+
}
19231936

19241937
return $this->processor->processAggregations($this, $this->connection->select($this->grammar->compileSelect($this), []));
19251938
}

0 commit comments

Comments
 (0)