Skip to content

Commit

Permalink
Add configurable date alias
Browse files Browse the repository at this point in the history
  • Loading branch information
Larsklopstra authored Feb 16, 2023
1 parent 9e80222 commit 70d8a4e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Trend.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class Trend

public string $dateColumn = 'created_at';

public string $dateAlias = 'date';

public function __construct(public Builder $builder)
{
}
Expand Down Expand Up @@ -87,12 +89,12 @@ public function aggregate(string $column, string $aggregate): Collection
$values = $this->builder
->toBase()
->selectRaw("
{$this->getSqlDate()} as date,
{$this->getSqlDate()} as {$this->dateAlias},
{$aggregate}({$column}) as aggregate
")
->whereBetween($this->dateColumn, [$this->start, $this->end])
->groupBy('date')
->orderBy('date')
->groupBy($this->dateAlias)
->orderBy($this->dateAlias)
->get();

return $this->mapValuesToDates($values);
Expand Down

0 comments on commit 70d8a4e

Please sign in to comment.