Skip to content

Commit b24b2b5

Browse files
authored
Merge pull request #4 from silas229/patch-1
Fix error on oracle databases
2 parents 5f2c94e + 345977b commit b24b2b5

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Widgets/ActivityChartWidget.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,23 @@ protected function getData(): array
9595
$fillColor = config('filament-activity-log.widgets.activity_chart.fill_color', 'rgba(16, 185, 129, 0.1)');
9696
$borderColor = config('filament-activity-log.widgets.activity_chart.border_color', '#10b981');
9797

98+
$driver = DB::getDriverName();
99+
100+
$dateExpression = match ($driver) {
101+
'oracle' => 'TRUNC(created_at)',
102+
default => 'DATE(created_at)',
103+
};
104+
98105
$data = Activity::query()
99-
->select(DB::raw('DATE(created_at) as date'), DB::raw('COUNT(*) as count'))
106+
->select(
107+
DB::raw("$dateExpression as activity_date"),
108+
DB::raw('COUNT(*) as count')
109+
)
100110
->where('created_at', '>=', now()->subDays($days))
101-
->groupBy('date')
102-
->orderBy('date')
111+
->groupBy(DB::raw($dateExpression))
112+
->orderBy(DB::raw($dateExpression))
103113
->get()
104-
->pluck('count', 'date');
114+
->pluck('count', 'activity_date');
105115

106116
return [
107117
'datasets' => [

0 commit comments

Comments
 (0)