TheRealPapa
TheRealPapa

Reputation: 4539

Accessing env values in page Javascript in Laravel 5.1

I cannot find how to achieve this. I am looking to access an env value in a page's javascript in Laravel 5.1. Any help is appreciated!

I have tried the following without success:

var AppImagePath = "<?php echo {!! env('APP_IMG_PATH') !!}?>";

var AppImagePath = {!! env('APP_IMG_PATH') !!};

Upvotes: 1

Views: 2882

Answers (2)

gaurav
gaurav

Reputation: 409

Hi this will work perfectly fine
it work for me.

var AppImagePath ='{!!getenv('AppImagePath')!!}';<br><br> 

alert(AppImagePath);

Upvotes: 0

manix
manix

Reputation: 14747

Try this:

<script>
    var AppImagePath = '{!! env("APP_IMG_PATH") !!}';
    console.log(AppImagePath);
</script>

Using <?php ?> is unnecessary when you are printing values with blade brackets. And in the second one, you forgot the quotes.

Upvotes: 4

Related Questions