Laravel - accessing .env variables
With Laravel, you should avoid environmental variables outside of your configuration files.
In your config files, you can use environmental variables, example in config/app.php:
'env' => env('APP_ENV', 'production'),
Then you can access this using the config helper: config('app.env')
.
This allows you to cache your configuration and still access these values, since env('APP_ENV')
will no longer work once your config is cached.
Route::get('/test', function () { return "it is".config('app.name');});
use env('ENVKEY')
Don't forget to clear cache sometime it cause because of cache.
php artisan config:clearphp artisan cache:clearcomposer dump-autoload
Formore info look at the doc