I’m having trouble with JSON rendering in Laravel 12 and Blade. The docs say to use {{ Js::from($map) }}, but it’s not working right. The data is there, but Blade isn’t handling it correctly.
I’m trying to create a hexagon map using a library. But I’m getting errors like Unexpected value translate(NaN NaN) and Unexpected value NaN NaN NaN NaN. It works fine if I hardcode the JSON though.
It seems you’re encountering a common issue with JSON serialization in Laravel. Have you considered using the @json Blade directive? It’s designed specifically for this purpose and might resolve your problem. Try modifying your JavaScript like this:
const hexes = @json($map);
This approach automatically applies proper JSON encoding and escaping. Also, ensure your $map variable in the controller is properly structured for the hexmap library. You might want to double-check the format of your HexTile model’s data. If the issue persists, try debugging by logging the raw $map data before passing it to the view to verify its structure.