Search code examples
javascriptphplaravellaravel-livewirealpine.js

Store PhP variable in JavaScript variable


I'm really new into web dev and I'm working on a project which uses the TALL stack:

  • Laravel Mix;
  • Livewire;
  • AlpineJS and;
  • TailwindCSS.

I want to get a PhP variable and store it in a JavaScript variable, so I can do jQuery/JavaScript stuff with it.

The PhP variable is <?php Auth::user()->kyc_status ?> and I would like to store it in a JavaScript variable called kycStatus. The idea could be represented by something like let kycStatus = <?php Auth::user()->kyc_status ?>

Thanks in advance.


Solution

  • <script>
        let kycStatus = {{ Auth::user()->kyc_status }}
    </script>