From 8ba30d75ead1d95a41d17c3d825fd95f24559aef Mon Sep 17 00:00:00 2001 From: peaklabs-dev <122374094+peaklabs-dev@users.noreply.github.com> Date: Tue, 6 Jan 2026 16:19:38 +0100 Subject: [PATCH] refactor: move all env sorting to one place --- .../Shared/EnvironmentVariable/All.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/app/Livewire/Project/Shared/EnvironmentVariable/All.php b/app/Livewire/Project/Shared/EnvironmentVariable/All.php index 07938d9d0..55e388b78 100644 --- a/app/Livewire/Project/Shared/EnvironmentVariable/All.php +++ b/app/Livewire/Project/Shared/EnvironmentVariable/All.php @@ -63,20 +63,30 @@ public function instantSave() public function getEnvironmentVariablesProperty() { - if ($this->is_env_sorting_enabled === false) { - return $this->resource->environment_variables()->orderBy('order')->get(); + $query = $this->resource->environment_variables() + ->orderByRaw("CASE WHEN is_required = true AND (value IS NULL OR value = '') THEN 0 ELSE 1 END"); + + if ($this->is_env_sorting_enabled) { + $query->orderBy('key'); + } else { + $query->orderBy('order'); } - return $this->resource->environment_variables; + return $query->get(); } public function getEnvironmentVariablesPreviewProperty() { - if ($this->is_env_sorting_enabled === false) { - return $this->resource->environment_variables_preview()->orderBy('order')->get(); + $query = $this->resource->environment_variables_preview() + ->orderByRaw("CASE WHEN is_required = true AND (value IS NULL OR value = '') THEN 0 ELSE 1 END"); + + if ($this->is_env_sorting_enabled) { + $query->orderBy('key'); + } else { + $query->orderBy('order'); } - return $this->resource->environment_variables_preview; + return $query->get(); } public function getDevView()