//在入口bootstrap/App.php中 $env = $app->detectEnvironment( function () use ($app) { $uname = php_uname('n'); $environment = 'local'; switch ($uname) { case 'xxx1': case 'xxx2': $environment = 'production'; break; case 'xxx3': $environment = 'testing'; break; default: $environment = 'local'; break; } putenv("APP_ENV={$environment}"); (new DotenvDotenv($app->basePath(), ".env.{$environment}"))->load(); } );