From ac14a327233a0b519ccbfb7bf8a21f19097f05ea Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Wed, 26 Nov 2025 09:37:18 +0100 Subject: [PATCH] fix: dispatch success message after transaction commits Move the success dispatch outside the DB transaction closure to ensure it only fires after the transaction has successfully committed. Use reference variable to track changes across the closure boundary. --- app/Livewire/SharedVariables/Environment/Show.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/Livewire/SharedVariables/Environment/Show.php b/app/Livewire/SharedVariables/Environment/Show.php index 6b1d35d14..328986cea 100644 --- a/app/Livewire/SharedVariables/Environment/Show.php +++ b/app/Livewire/SharedVariables/Environment/Show.php @@ -99,10 +99,9 @@ public function submit() private function handleBulkSubmit() { $variables = parseEnvFormatToArray($this->variables); + $changesMade = false; - DB::transaction(function () use ($variables) { - $changesMade = false; - + DB::transaction(function () use ($variables, &$changesMade) { // Delete removed variables $deletedCount = $this->deleteRemovedVariables($variables); if ($deletedCount > 0) { @@ -114,11 +113,12 @@ private function handleBulkSubmit() if ($updatedCount > 0) { $changesMade = true; } - - if ($changesMade) { - $this->dispatch('success', 'Environment variables updated.'); - } }); + + // Only dispatch success after transaction has committed + if ($changesMade) { + $this->dispatch('success', 'Environment variables updated.'); + } } private function deleteRemovedVariables($variables)