Laravel .env variable always returns null

前端 未结 7 2373
误落风尘
误落风尘 2021-01-05 01:14

I added this variable to .env file

STRIPE_SECRET=a12345

I would like to dump the variable using routes/web.php

&         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-05 01:19

    env(...) function will return null after you cached the config. (starting from laravel 5.2 till current 5.7)

    The documentation says

    If you are using the config:cache command during deployment, you must make sure that you are only calling the env function from within your configuration files, and not from anywhere else in your application.

    So the correct answer would be to

    If you are calling env from within your application, it is strongly recommended you add proper configuration values to your configuration files and call env from that location instead, allowing you to convert your env calls to config calls.

    And I quoted it from the same documentation

    But for a quick fix this will do:

    php artisan config:clear

提交回复
热议问题