Skip to content
Discussion options

You must be logged in to vote

It's not a good idea to use the blade directives like this - they are built using a basic Regex, and can't handle complex structures. Even the escaping brackets ({{ ... }}) is regex based and not recommended for multi-line or super complex expressions.

I'd recommend setting your array in a variable in your controller or a <?php ... ?> section at the start of your template and then rendering that variable using the JS facade: https://laravel.com/docs/10.x/blade#rendering-json

<?php
$array = [
    'active_task' => $active_task,
    'styles' => $styles,
    'tasks_max' => 10,
    'tasks_default' => 3
];
?>

<script>
var wtf = {{ Js::from($array) }};;
</script>

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by crynobone
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #49132 on November 27, 2023 00:33.