Fix compatibilité MySQL : NULLS LAST et order withCount/select

- DbCompat::nullsLast() : syntaxe portable pgsql/mysql pour ORDER BY NULLS LAST
- RechercheController, ExportController : remplace 'nom ASC NULLS LAST' (pgsql only)
- CarteController : select() avant withCount() pour ne pas effacer le COUNT subquery

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-05 18:46:31 +02:00
parent 6271963a94
commit bc4dd29ae7
4 changed files with 17 additions and 5 deletions
+2 -2
View File
@@ -21,8 +21,8 @@ class CarteController extends Controller
->whereHas('sources.releves')
->with([
'sources' => function ($q) {
$q->withCount('releves')
->select('id', 'nom', 'lieu_id', 'status', 'annee_debut', 'annee_fin')
$q->select('id', 'nom', 'lieu_id', 'status', 'annee_debut', 'annee_fin')
->withCount('releves')
->orderBy('nom');
},
])
+1 -1
View File
@@ -90,7 +90,7 @@ class ExportController extends Controller
$query->whereRaw('date_evenement <= ?', [$request->integer('annee_fin') . '-12-31']);
}
$releves = $query->orderByRaw('nom ASC NULLS LAST')->get();
$releves = $query->orderByRaw(DbCompat::nullsLast('nom'))->get();
if ($releves->isEmpty()) {
return back()->with('error', 'Aucun relevé à exporter.');
+2 -2
View File
@@ -88,8 +88,8 @@ class RechercheController extends Controller
// ── Tri + pagination ────────────────────────────────────────────────
$total = $query->count();
$resultats = $query
->orderByRaw('nom ASC NULLS LAST')
->orderByRaw('date_evenement ASC NULLS LAST')
->orderByRaw(DbCompat::nullsLast('nom'))
->orderByRaw(DbCompat::nullsLast('date_evenement'))
->paginate(25)
->withQueryString();