使用\Config::get('app.env');
而不是env(APP_ENV);
因为您最终会遇到相同的错误,这对实时网站不利。
如果要从 ENV 添加自定义变量,请进入配置应用程序并找到以下内容:
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services your application utilizes. Set this in your ".env" file.
|
*/
'env' => env('APP_ENV', 'production'),
在“”下添加一个新行'env' => env('APP_ENV', 'production'),
,例如,它可能如下:
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services your application utilizes. Set this in your ".env" file.
|
*/
'env' => env('APP_ENV', 'production'),
'key' => env('APP_KEY'),
您可以像这样调用“key”变量:
\Config::get('app.key');
每当您向应用程序环境添加一个新变量(如“key”)时,您都需要使用它config:cache
来重置缓存。