根据不同的环境有不同的配置,laravel中,可以把配置写到.env文件中
在系统中,可以使用env(key, "默认值")来获取env中的配置信息
在laravel中运行时,会运行函数 checkForSpecificEnvironmentFile, 根据不同的环境加载不同的配置。
Illuminate\Foundation\Bootstrap\DetectEnvironment
protected function checkForSpecificEnvironmentFile($app) { if (! env('APP_ENV')) { return; } $file = $app->environmentFile().'.'.env('APP_ENV'); if (file_exists($app->environmentPath().'/'.$file)) { $app->loadEnvironmentFrom($file); } }
先判断$_SERVER['APP_ENV']是否存在,存在的话,就根据环境变量加载后缀是环境变量的文件
.env.local
.env.testing
.env.production