TheRealPapa TheRealPapa - 1 year ago 90
Javascript Question

Accessing env values in page Javascript in Laravel 5.1

I cannot find how to achieve this. I am looking to access an

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') !!};

Answer Source

Try this:

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

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download