Laravel .env variable always returns null

前端 未结 7 2299
误落风尘
误落风尘 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:41

    You can clear configuration cache using following commands

    php artisan config:clear 
    php artisan optimize
    php artisan config:cache
    

    Also make sure

    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. 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.

    Reference link:

    Update 1:

    Also make sure you have renamed .env.example to .env file by default laravel have .env.example

    Update 2

    As per your new update question your env file have STRIPE not STRIPE_SECRET so you have access like this if its not typo error in question

    env('STRIPE')
    

提交回复
热议问题