From 6271963a944a84be02b688657c29a5dee4b2009c Mon Sep 17 00:00:00 2001 From: yann64 Date: Fri, 5 Jun 2026 07:47:30 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20dashboard=20admin=20:=20requ=C3=AAte=20ac?= =?UTF-8?q?tivit=C3=A9=20mensuelle=20compatible=20MySQL/PostgreSQL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit to_char/date_trunc remplacés par DATE_FORMAT pour MySQL. Co-Authored-By: Claude Sonnet 4.6 --- .../Controllers/Admin/DashboardController.php | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) 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',