From 3d632a4441fa612a6f85ca0c43b355545caf1cb6 Mon Sep 17 00:00:00 2001 From: Nico Stapelbroek Date: Sun, 25 Nov 2018 16:45:49 +0100 Subject: [PATCH] Add support for empty values in the persistEnv method --- app/Console/Commands/InstallCommand.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/InstallCommand.php b/app/Console/Commands/InstallCommand.php index 1ece3958..6ecc26ce 100644 --- a/app/Console/Commands/InstallCommand.php +++ b/app/Console/Commands/InstallCommand.php @@ -389,11 +389,12 @@ class InstallCommand extends Command $envKey = strtoupper($key); $envValue = env($envKey) ?: 'null'; - file_put_contents($path, str_replace( - "{$envKey}={$envValue}", - "{$envKey}={$value}", - file_get_contents($path) - )); + $envFileContents = file_get_contents($path); + $envFileContents = str_replace("{$envKey}={$envValue}", "{$envKey}={$value}", $envFileContents, $count); + if ($count < 1 && $envValue === 'null') { + $envFileContents = str_replace("{$envKey}=", "{$envKey}={$value}", $envFileContents); + } + file_put_contents($path, $envFileContents); } catch (InvalidPathException $e) { throw $e; }