I am new to Lavarel and I wrote this portion of code to add my collection to a javascript array and it does not seem to work.
$(document).ready(function() {
var data = [];
@foreach($products as $product )
data.push({'{{ $product->id }}' : '{{ $product->name }}'});
@endforeach
// Im trying to get a variable which looks like this
// data: [
// {
// id: 'The ID goes here',
// text: 'Text to display'
// },
// // ... more data objects ...
// ]
});
Kindly help me solve this problem