Skip to content

Commit

Permalink
Fix Query builder and Eloquent builder types in sub-queries
Browse files Browse the repository at this point in the history
  • Loading branch information
eliseekn committed Sep 16, 2023
1 parent b3c6353 commit 65be1fa
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions src/LaravelMetrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ protected function metricsData(): mixed
->selectRaw($this->asData())
->whereYear($this->dateColumn, $this->year)
->whereMonth($this->dateColumn, $this->month)
->when($this->count === 1, function (QueryBuilder $query) {
->when($this->count === 1, function (Builder|QueryBuilder $query) {
return $query->where(DB::raw("day($this->dateColumn)"), $this->day);
})
->when($this->count > 1, function (QueryBuilder $query) {
->when($this->count > 1, function (Builder|QueryBuilder $query) {
return $query->whereBetween(DB::raw("day($this->dateColumn)"), [
Carbon::now()->subDays($this->count)->day, $this->day
]);
Expand All @@ -200,10 +200,10 @@ protected function metricsData(): mixed
->selectRaw($this->asData())
->whereYear($this->dateColumn, $this->year)
->whereMonth($this->dateColumn, $this->month)
->when($this->count === 1, function (QueryBuilder $query) {
->when($this->count === 1, function (Builder|QueryBuilder $query) {
return $query->where(DB::raw($this->formatPeriod(Period::WEEK->value)), $this->week);
})
->when($this->count > 1, function (QueryBuilder $query) {
->when($this->count > 1, function (Builder|QueryBuilder $query) {
return $query->whereBetween(DB::raw($this->formatPeriod(Period::WEEK->value)), [
Carbon::now()->subWeeks($this->count)->week, $this->week
]);
Expand All @@ -213,10 +213,10 @@ protected function metricsData(): mixed
Period::MONTH->value => $this->builder
->selectRaw($this->asData())
->whereYear($this->dateColumn, $this->year)
->when($this->count === 1, function (QueryBuilder $query) {
->when($this->count === 1, function (Builder|QueryBuilder $query) {
return $query->where(DB::raw($this->formatPeriod(Period::MONTH->value)), $this->month);
})
->when($this->count > 1, function (QueryBuilder $query) {
->when($this->count > 1, function (Builder|QueryBuilder $query) {
return $query->whereBetween(DB::raw($this->formatPeriod(Period::MONTH->value)), [
$this->parseMonth(), $this->month
]);
Expand All @@ -225,10 +225,10 @@ protected function metricsData(): mixed

Period::YEAR->value => $this->builder
->selectRaw($this->asData())
->when($this->count === 1, function (QueryBuilder $query) {
->when($this->count === 1, function (Builder|QueryBuilder $query) {
return $query->where(DB::raw($this->formatPeriod(Period::YEAR->value)), $this->year);
})
->when($this->count > 1, function (QueryBuilder $query) {
->when($this->count > 1, function (Builder|QueryBuilder $query) {
return $query->whereBetween(DB::raw($this->formatPeriod(Period::YEAR->value)), [
Carbon::now()->subYears($this->count)->year, $this->year
]);
Expand Down Expand Up @@ -257,10 +257,10 @@ protected function trendsData(): Collection
->selectRaw($this->asData() . ", " . $this->asLabel(Period::DAY->value))
->whereYear($this->dateColumn, $this->year)
->whereMonth($this->dateColumn, $this->month)
->when($this->count === 1, function (QueryBuilder $query) {
->when($this->count === 1, function (Builder|QueryBuilder $query) {
return $query->where(DB::raw("day($this->dateColumn)"), $this->day);
})
->when($this->count > 1, function (QueryBuilder $query) {
->when($this->count > 1, function (Builder|QueryBuilder $query) {
return $query->whereBetween(DB::raw("day($this->dateColumn)"), [
Carbon::now()->subDays($this->count)->day, $this->day
]);
Expand All @@ -273,10 +273,10 @@ protected function trendsData(): Collection
->selectRaw($this->asData() . ", " . $this->asLabel(Period::WEEK->value))
->whereYear($this->dateColumn, $this->year)
->whereMonth($this->dateColumn, $this->month)
->when($this->count === 1, function (QueryBuilder $query) {
->when($this->count === 1, function (Builder|QueryBuilder $query) {
return $query->where(DB::raw($this->formatPeriod(Period::WEEK->value)), $this->week);
})
->when($this->count > 1, function (QueryBuilder $query) {
->when($this->count > 1, function (Builder|QueryBuilder $query) {
return $query->whereBetween(DB::raw($this->formatPeriod(Period::WEEK->value)), [
Carbon::now()->subWeeks($this->count)->week, $this->week
]);
Expand All @@ -288,10 +288,10 @@ protected function trendsData(): Collection
Period::MONTH->value => $this->builder
->selectRaw($this->asData() . ", " . $this->asLabel(Period::MONTH->value))
->whereYear($this->dateColumn, $this->year)
->when($this->count === 1, function (QueryBuilder $query) {
->when($this->count === 1, function (Builder|QueryBuilder $query) {
return $query->where(DB::raw($this->formatPeriod(Period::MONTH->value)), $this->month);
})
->when($this->count > 1, function (QueryBuilder $query) {
->when($this->count > 1, function (Builder|QueryBuilder $query) {
return $query->whereBetween(DB::raw($this->formatPeriod(Period::MONTH->value)), [
$this->parseMonth(), $this->month
]);
Expand All @@ -302,10 +302,10 @@ protected function trendsData(): Collection

Period::YEAR->value => $this->builder
->selectRaw($this->asData() . ", " . $this->asLabel(Period::YEAR->value))
->when($this->count === 1, function (QueryBuilder $query) {
->when($this->count === 1, function (Builder|QueryBuilder $query) {
return $query->where(DB::raw($this->formatPeriod(Period::YEAR->value)), $this->year);
})
->when($this->count > 1, function (QueryBuilder $query) {
->when($this->count > 1, function (Builder|QueryBuilder $query) {
return $query->whereBetween(DB::raw($this->formatPeriod(Period::YEAR->value)), [
Carbon::now()->subYears($this->count)->year, $this->year
]);
Expand Down

0 comments on commit 65be1fa

Please sign in to comment.