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:
parent
c548013e2d
commit
b803a137f6
2 changed files with 6 additions and 4 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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 &&
|
||||
|
|
|
|||
Loading…
Reference in a new issue