I am passing an array from my controller.
Now, I put this code inside my Laravel 6.* Blade View,
<script>
var app = <?php echo json_encode($array); ?>;
</script>
This works just fine.
However, if I put the same piece of line (or any of the following lines) inside my custom app.js file, this doesn't work.
var app = <?php echo json_encode($array); ?>;
var app = {!! json_encode($array->toArray()) !!};
var app = '<?php echo json_encode($array); ?>';
Each time I am getting an invalid syntax error.
I am not sure if this is a valid ques for StackOverflow, but I have already tried all other similar solutions and none of them is working for me.