Laravel .env variable always returns null

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

    First, there is no STRIPE_SECRET inside your .env file(As per before edit the question). So please make sure that your .env must have this variable. You should clear your configuration cache by executing following commands in the same order

    php artisan config:cache
    php artisan config:clear 
    

    Laravel cache your configuration files so the execution become faster. So everytime when you change the configuration files on server, you should clear the cache.

    Additionally you can run these commands also to clear the other caches

    php artisan cache:clear   //for clearing the cache
    php artisan view:clear    //for clearing the compiled views
    php artisan route:clear   //for clearing the routes cache
    

    You can also create the routes for these commands and call the commands from the code also as

    Route::get('/cache-clear', function() {
        $exitCode = Artisan::call('cache:clear');
        echo "Cache Cleard: ".$exitCode;
    });
    
    Route::get('/view-clear', function() {
        $exitCode = Artisan::call('view:clear');
        echo "View Cleard: ".$exitCode;
    });
    
    Route::get('/route-cache', function() {
        $exitCode = Artisan::call('route:cache');
        echo "Route Cached: ".$exitCode;
    });
    
    Route::get('/route-clear', function() {
        $exitCode = Artisan::call('route:clear');
        echo "Route Cache Cleared: ".$exitCode;
    });
    
    Route::get('/config-cache', function() {
        $exitCode = Artisan::call('config:cache');
        echo "Config Cached: ".$exitCode;
    });
    
    Route::get('/config-clear', function() {
        $exitCode = Artisan::call('config:clear');
        echo "Config Cache Cleared: ".$exitCode;
    });
    

提交回复
热议问题