alexeymezenin / laravel-best-practices

Laravel best practices
11.43k stars 2.38k forks source link

Do not get data from the .env file directly, why? #118

Closed abyssgoing closed 2 years ago

abyssgoing commented 2 years ago

I am using the bad way.

$apiKey = env('API_KEY');
alexeymezenin commented 2 years ago

@PengYilong it's a good idea to do that to avoid obscurity when working in teams. Another reason is configuration caching:

If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded; therefore, the env function will only return external, system level environment variables.

abyssgoing commented 2 years ago

thanks @alexeymezenin