diff --git a/resources/views/admin/dashboard.blade.php b/resources/views/admin/dashboard.blade.php index 64b3c14..5fa96f8 100644 --- a/resources/views/admin/dashboard.blade.php +++ b/resources/views/admin/dashboard.blade.php @@ -741,12 +741,21 @@ new Chart(document.getElementById('typeChart'), { // ── Country Chart ─────────────────────────────────────────────── @if($viewsByCountry->isNotEmpty()) +@php + // Blade's @json() parser can't handle a multi-line arrow function with + // a `[` array literal inside its body — the directive reads until the + // closing paren and sees the inner `[` as an unmatched bracket. Build + // the array in PHP first, then hand the plain variable to @json(). + $countryChartData = $viewsByCountry->map(function ($r) { + return [ + 'country' => $r->country, + 'country_name' => $r->country_name ?? \App\Data\Countries::name($r->country), + 'total' => $r->total, + ]; + })->values(); +@endphp (function() { - const countryData = @json($viewsByCountry->map(fn($r) => [ - 'country' => $r->country, - 'country_name' => $r->country_name ?? \App\Data\Countries::name($r->country), - 'total' => $r->total, - ])->values()); + const countryData = @json($countryChartData); const labels = countryData.map(r => r.country_name || r.country || ''); const values = countryData.map(r => r.total); const maxVal = Math.max(...values);