Fix dashboard admin : requête activité mensuelle compatible MySQL/PostgreSQL
to_char/date_trunc remplacés par DATE_FORMAT pour MySQL. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -50,12 +50,21 @@ class DashboardController extends Controller
|
||||
->take(10)
|
||||
->get();
|
||||
|
||||
// Activité mensuelle des 6 derniers mois
|
||||
// Activité mensuelle des 6 derniers mois (compatible MySQL et PostgreSQL)
|
||||
$driver = config('database.default');
|
||||
if ($driver === 'pgsql') {
|
||||
$activiteMensuelle = Releve::selectRaw("to_char(date_trunc('month', created_at), 'Mon YYYY') as mois, count(*) as total")
|
||||
->where('created_at', '>=', now()->subMonths(5)->startOfMonth())
|
||||
->groupByRaw("date_trunc('month', created_at)")
|
||||
->orderByRaw("date_trunc('month', created_at)")
|
||||
->get();
|
||||
} else {
|
||||
$activiteMensuelle = Releve::selectRaw("DATE_FORMAT(created_at, '%b %Y') as mois, count(*) as total")
|
||||
->where('created_at', '>=', now()->subMonths(5)->startOfMonth())
|
||||
->groupByRaw("DATE_FORMAT(created_at, '%Y-%m')")
|
||||
->orderByRaw("DATE_FORMAT(created_at, '%Y-%m')")
|
||||
->get();
|
||||
}
|
||||
|
||||
return view('admin.dashboard', compact(
|
||||
'sourcesByStatus', 'totalSources', 'totalReleves',
|
||||
|
||||
Reference in New Issue
Block a user