fix(admin): dashboard country-chart blade parse error
@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) <[email protected]>
This commit is contained in:
1 parent
a2752643e9
commit
d1fd76c278
1 file changed
+12
-3
@@ -741,12 +741,21 @@ new Chart(document.getElementById('typeChart'), {
|
|||||||
|
|
||||||
// ── Country Chart ───────────────────────────────────────────────
|
// ── Country Chart ───────────────────────────────────────────────
|
||||||
@if($viewsByCountry->isNotEmpty())
|
@if($viewsByCountry->isNotEmpty())
|
||||||
(function() {
|
@php
|
||||||
const countryData = @json($viewsByCountry->map(fn($r) => [
|
// 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' => $r->country,
|
||||||
'country_name' => $r->country_name ?? \App\Data\Countries::name($r->country),
|
'country_name' => $r->country_name ?? \App\Data\Countries::name($r->country),
|
||||||
'total' => $r->total,
|
'total' => $r->total,
|
||||||
])->values());
|
];
|
||||||
|
})->values();
|
||||||
|
@endphp
|
||||||
|
(function() {
|
||||||
|
const countryData = @json($countryChartData);
|
||||||
const labels = countryData.map(r => r.country_name || r.country || '');
|
const labels = countryData.map(r => r.country_name || r.country || '');
|
||||||
const values = countryData.map(r => r.total);
|
const values = countryData.map(r => r.total);
|
||||||
const maxVal = Math.max(...values);
|
const maxVal = Math.max(...values);
|
||||||
|
|||||||
Reference in new issue
Block a user