mirror of
https://github.com/tiennm99/coolify.git
synced 2026-09-10 02:17:21 +00:00
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:
@@ -543,10 +543,7 @@ class GlobalSearch extends Component
|
||||
});
|
||||
|
||||
// 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 @@ class Environment extends BaseModel
|
||||
});
|
||||
}
|
||||
|
||||
public static function ownedByCurrentTeam()
|
||||
{
|
||||
return Environment::whereRelation('project.team', 'id', currentTeam()->id)->orderBy('name');
|
||||
}
|
||||
|
||||
public function isEmpty()
|
||||
{
|
||||
return $this->applications()->count() == 0 &&
|
||||
|
||||
Reference in New Issue
Block a user