简体   繁体   English

Laravel config/app.php 和.env 文件中的应用程序环境变量

[英]Laravel Application Environment variable in config/app.php and .env file

In my config/app.php file, the app environment variable it set like this: 'env' => env('APP_ENV', 'production'), .在我的 config/app.php 文件中,它设置的应用程序环境变量如下: 'env' => env('APP_ENV', 'production'), Meanwhile in the.env file, the app environment is set to APP_ENV=local .同时在 .env 文件中,应用环境设置为APP_ENV=local

It appears as though only the.env file matters.似乎只有 .env 文件很重要。 The app behaves as though the environment is local.该应用程序的行为就像环境是本地的一样。 php artisan env returns php artisan env返回

Current application environment: local

Is there some instance when I should make modifications to the app.php file instead of the.env file?在某些情况下我应该修改 app.php 文件而不是 .env 文件吗? Should the variables in the app file just be ignored?应用程序文件中的变量是否应该被忽略?

As in the docs env second argument如 docs env 第二个参数

The second value passed to the env function is the "default value".传递给 env function 的第二个值是“默认值”。 This value will be used if no environment variable exists for the given key.如果给定键不存在环境变量,则将使用此值。 So you get value from te env file.因此,您可以从 te env 文件中获得价值。

If you dont want to use .env settings then simply commented out or remove them.如果您不想使用.env设置,则只需注释掉或删除它们。 By doing this, system will pick your defined values from the config/app.php file.通过这样做,系统将从config/app.php文件中选择您定义的值。

For example: 'env' => env('APP_ENV', 'YOUR ENVIRONMENT VALUE')例如: 'env' => env('APP_ENV', 'YOUR ENVIRONMENT VALUE')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM