Laravel - accessing .env variables
Route::get('/test', function () {
return "it is".config('app.name');
});
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.