Search code examples
phplaravelrecaptcha

get env varaible with script jquery


I´m trying to get one variable from my .env in Laravel 5.8, but it always returns a string.

{!! getenv("RECAPTCHAV3_SITEKEY") !!}

I have this code:

e.preventDefault();
key = '{!! getenv("RECAPTCHAV3_SITEKEY") !!}';

console.log(key);

I also tried:

e.preventDefault();
key = '{{ env("RECAPTCHAV3_SITEKEY") }}';
    
console.log(key);

But I always get the same result. I need to do this to generate google Recaptcha with jQuery and Ajax when I click on my login or register button. How I can to do this?


Solution

  • Maybe try...

    <script>
    
        let key = '{{ config('RECAPTCHAV3_SITEKEY') }}';
    
        alert(key);
    
    </script>