根据不同的环境有不同的配置,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

相关文章:

  • 2022-12-23
  • 2021-04-02
  • 2022-12-23
  • 2021-08-18
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-04-24
  • 2021-08-19
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案