Laravel .env variable always returns null

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

    The main reason upon your issue is that you are caching your configuration. When running php artisan config:cache you're storing your configuration in your cache, and the next time Laravel will boot up it won't read the .env file because it detects that the configuration has been stored in the cache. Environment file should be used only to setup configuration files and then to access the value you're looking for you should use ONLY the config method.

    Let's assume that you have the file config/stripe.php that consists of this content:

    <?php
    
    return [
        'secret' => env('STRIPE_SECRET', '')
    ];
    

    Once you run php artisan config:cache access this value using ONLY the syntax config('stripe.secret') through your application code. Every time you update your config files and your .env you need to run php artisan config:cache again.

    0 讨论(0)
提交回复
热议问题