1

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?

Karl Hill
  • 12,937
  • 5
  • 58
  • 95
daviserraalonso
  • 75
  • 1
  • 13
  • Does this answer your question? [How to access the laravel .env variables inside javascript?](https://stackoverflow.com/questions/35683562/how-to-access-the-laravel-env-variables-inside-javascript) – Indra Feb 03 '21 at 12:31
  • @Indra not... returned for me a syntax error. – daviserraalonso Feb 03 '21 at 12:33
  • check the answers there. one of those is right for you. Please remove your question since it's a duplicate – Indra Feb 03 '21 at 12:36
  • @Indra i check this question and always returned a string "{{ env("RECAPTCHAV3_SITEKEY") }}" not my key – daviserraalonso Feb 03 '21 at 12:41
  • @daviserraalonso Did you try use `key = '{{ env('RECAPTCHAV3_SITEKEY') }}';` instead `key = '{{ env("RECAPTCHAV3_SITEKEY") }}';`? – Thân LƯƠNG Đình Feb 03 '21 at 15:03

1 Answers1

0

Maybe try...

<script>

    let key = '{{ config('RECAPTCHAV3_SITEKEY') }}';

    alert(key);

</script>
Karl Hill
  • 12,937
  • 5
  • 58
  • 95