2015-10-02 03:22
浏览 75

在Laravel 5.1中访问页面Javascript中的env值

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

图片转代码服务由CSDN问答提供 功能建议

我找不到如何实现这一点。 我希望在Laravel 5.1中的页面的javascript中访问 env 值。 感谢任何帮助!


  var AppImagePath =“&lt;?php echo {!!  env('APP_IMG_PATH')!!}?&gt;“; 
var AppImagePath = {!!  env('APP_IMG_PATH')!!}; 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanlan7239 2015-10-02 04:17

    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.

    打赏 评论
  • douxun1934 2016-11-18 08:03

    Hi this will work perfectly fine
    it work for me.

    var AppImagePath ='{!!getenv('AppImagePath')!!}';<br><br> 
    打赏 评论

相关推荐 更多相似问题