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