From d1fd76c278e00cfd221000507aa8b8e09c08cfff Mon Sep 17 00:00:00 2001 From: ghassan Date: Wed, 21 Oct 2026 10:12:32 +0300 Subject: [PATCH] fix(admin): dashboard country-chart blade parse error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @json() with a multi-line arrow function whose body is an array literal confuses Blade's directive parser — it reads the inner '[' as an unmatched bracket and bails out with "Unclosed '[' on line 744 does not match ')'". Precompute the array in a plain @php block and hand the already-evaluated collection to @json() instead. The bug has been dormant because the compiled view was cached. It surfaced the moment the view cache got cleared. Co-Authored-By: Claude Opus 4.7 (1M context) --- resources/views/admin/dashboard.blade.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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);