如何使用Blade传递PHP变量来遍历JavaScript代码

I am using chart.js to show some data, and everything was working fine when the code was this:

JavaScript/Blade

 var pieDataAssignments = [

                @for($i = 0;$i<count($name);$i++)

            {
                value: {!! count(array_filter($ass_c,create_function('$a','return $a=="'.$name[$i].'";')))!!},
                color: 'pink',
                highlight: "#eaa5a2",
                label: 'Subject'
            },

                @endfor

        ];

Then I thought it was working, which it was, and I thought to start customising the Pie Chart.

Firstly I tried inserting the value for each variable individually, e.g.

color: {!! $colour[$i] !!},
etc...

That just prevented the pie chart from appearing, which led me to ponder my failure..

I then tried to insert everything into the first Blade call, like so:

Blade

{!!'

{
    value:'.count(array_filter($ass_c,create_function('$a','return $a=="'.$name[$i].'";'))).',
    color: "'.$colour[$i].'",
    highlight: "#eaa5a2",
    label: "hi"
},

'!!}

But still, it did not show up.

How can I go about looping JavaScript code and passing php variables at the same time? I don't know what else to try and I can't find anything online apart from telling me to do exactly what I tried.

Thank you in advance.

I fixed the issue, the code I had was recreating the array inside it's own instance. The code that now works is the following:

var pieDataAssignments = [

        @for($i = 0;$i<count($name);$i++)

        {!!'

        {
            value:'.count(array_filter($ass_c,create_function('$a','return $a=="'.$name[$i].'";'))).',
            color: "'.$colour[$i].'",
            highlight: "#eaa5a2",
            label: "'.$name[$i].'"
        },

        '!!}



        @endfor

];