From b803a137f6c4b35cfec1b6ce843c89f47a25a368 Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Wed, 8 Oct 2025 19:58:36 +0200 Subject: [PATCH] refactor(global-search, environment): streamline environment retrieval with new query method - Replaced the inline query for fetching environments in GlobalSearch with a new static method `ownedByCurrentTeam` in the Environment model, enhancing code readability and maintainability. - This change simplifies the logic for retrieving environments associated with the current team, promoting better organization of query logic within the model. --- app/Livewire/GlobalSearch.php | 5 +---- app/Models/Environment.php | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Livewire/GlobalSearch.php b/app/Livewire/GlobalSearch.php index f98b8e09a..87008e45e 100644 --- a/app/Livewire/GlobalSearch.php +++ b/app/Livewire/GlobalSearch.php @@ -543,10 +543,7 @@ private function loadSearchableItems() }); // Get all environments - $environments = Environment::query() - ->whereHas('project', function ($query) { - $query->where('team_id', auth()->user()->currentTeam()->id); - }) + $environments = Environment::ownedByCurrentTeam() ->with('project') ->withCount(['applications', 'services']) ->get() diff --git a/app/Models/Environment.php b/app/Models/Environment.php index bfeee01c9..c2ad9d2cb 100644 --- a/app/Models/Environment.php +++ b/app/Models/Environment.php @@ -35,6 +35,11 @@ protected static function booted() }); } + public static function ownedByCurrentTeam() + { + return Environment::whereRelation('project.team', 'id', currentTeam()->id)->orderBy('name'); + } + public function isEmpty() { return $this->applications()->count() == 0 &&