diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index a26875b..134ca1e 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -50,12 +50,21 @@ class DashboardController extends Controller ->take(10) ->get(); - // Activité mensuelle des 6 derniers mois - $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(); + // 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',