I'm building a site with Laravel 8 and trying to pass PHP variables into JavaScript. At first I was using this kind of construction in my Blade file:
<script>
let x = {{ $x }};
</script>
but this gets mangled by the format-on-save action in VSCode because the braces get interpreted as JavaScript and separated by spaces.
As an alternative, I've tried to install Laracasts/Utilities, following the instructions here. After carrying out all the steps, however, the controller doesn't recognize JavaScript:
<?php
namespace App\Http\Controllers;
...
use JavaScript; // <--- no info on mouseover
class XController extends Controller
{
public function f()
{
JavaScript::put([...]); // <--- Undefined type 'JavaScript'
I'm a beginner at PHP and Laravel, so this is beyond me. It seems that the alias isn't working properly (even though I listed it in aliases in config/app.php) based on the fact that no information pops up when I mouse over use JavaScript in VSCode. I've tried running magic commands like php artisan optimize:clear, php artisan config:clear, and composer dump-autoload, but they didn't change anything and maybe aren't relevant. What else can I try at this point?