DEV Community

Discussion on: Laravel How to Get .env Variable in Controller and Blade

Collapse
 
jason2605 profile image
Jason_000

You generally do not ever want to use env() outside of laravel configuration files and should instead strive to use the config() helper instead.

The reason for this is when you go to use laravels config:cache command (which would be used in production) env variables are wiped, so your code above wouldn't work as expected.

See here: laravel.com/docs/8.x/configuration...

For accessing the current environment you can use the helper facade that laravel provides for you as well: laravel.com/docs/8.x/configuration...