diff --git a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php index b1fa237e0..3f8b73f7b 100644 --- a/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php +++ b/app/Http/Livewire/Project/Shared/EnvironmentVariable/All.php @@ -55,12 +55,17 @@ public function saveVariables($isPreview) { if ($isPreview) { $variables = parseEnvFormatToArray($this->variablesPreview); + $this->resource->environment_variables_preview()->whereNotIn('key', array_keys($variables))->delete(); } else { $variables = parseEnvFormatToArray($this->variables); + $this->resource->environment_variables()->whereNotIn('key', array_keys($variables))->delete(); } foreach ($variables as $key => $variable) { - $found = $this->resource->environment_variables()->where('key', $key)->first(); - $foundPreview = $this->resource->environment_variables_preview()->where('key', $key)->first(); + if ($isPreview) { + $found = $this->resource->environment_variables_preview()->where('key', $key)->first(); + } else { + $found = $this->resource->environment_variables()->where('key', $key)->first(); + } if ($found) { if ($found->is_shown_once) { continue; @@ -68,14 +73,6 @@ public function saveVariables($isPreview) $found->value = $variable; $found->save(); continue; - } - if ($foundPreview) { - if ($foundPreview->is_shown_once) { - continue; - } - $foundPreview->value = $variable; - $foundPreview->save(); - continue; } else { $environment = new EnvironmentVariable(); $environment->key = $key;