I’m working with Laravel and trying to send JSON data to my Blade template. I followed the official docs but I’m having trouble with the Js::from()
helper method.
<script>
const coordinates = {{ Js::from($gridData) }};
console.log(coordinates);
var mapInstance = new GridLib.create(document.getElementById('mapContainer'),
{
'display': {'visible':true},
'text': {
'visible': true,
'truncate': true,
'formatter': function(text,attributes) {
return attributes.cell.x + ", " + attributes.cell.y;
}
},
'gridconfig':{
"type":"offset-r",
"cells": coordinates,
}
}
);
</script>
When I use the Blade helper, my grid library shows errors like Unexpected value translate(NaN NaN)
and Unexpected value NaN parsing viewBox
. But if I manually copy the console output and paste it directly into the code, everything works fine.
My controller code looks like this:
$cells = GridCell::orderBy('position', 'asc')->get()->toArray();
$cells["start"] = array("x"=>0, "y"=>0);
return view('dashboard', ["gridData" => json_encode($cells)]);
The data seems correct when logged, but something about how Blade processes it breaks the grid rendering. Any ideas what might be wrong?