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.
This commit is contained in:
Andras Bacsai 2025-10-08 19:58:36 +02:00
parent c548013e2d
commit b803a137f6
2 changed files with 6 additions and 4 deletions

View file

@ -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()

View file

@ -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 &&