From 99354f0d7de8a6e053ae10f851bcd758efb4520d Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Mon, 24 Jun 2024 18:41:44 +0200 Subject: [PATCH] Refactor default_environment method to handle projects with 0 environments --- app/Models/Project.php | 10 +++++++--- resources/views/livewire/dashboard.blade.php | 2 +- resources/views/livewire/project/index.blade.php | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/Models/Project.php b/app/Models/Project.php index 1f39aa725..b7d34e876 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -116,10 +116,14 @@ public function databases() public function default_environment() { $default = $this->environments()->where('name', 'production')->first(); - if (! $default) { - $default = $this->environments()->get()->sortBy('created_at')->first(); + if ($default) { + return $default->name; + } + $default = $this->environments()->get(); + if ($default->count() > 0) { + return $default->sortBy('created_at')->first()->name; } - return $default; + return null; } } diff --git a/resources/views/livewire/dashboard.blade.php b/resources/views/livewire/dashboard.blade.php index c1dd375ff..a6eb231d4 100644 --- a/resources/views/livewire/dashboard.blade.php +++ b/resources/views/livewire/dashboard.blade.php @@ -23,7 +23,7 @@
@foreach ($projects as $project)
+ onclick="gotoProject('{{ $project->uuid }}','{{ $project->default_environment() }}')">
{{ $project->name }}
diff --git a/resources/views/livewire/project/index.blade.php b/resources/views/livewire/project/index.blade.php index 76bae7a91..92d4a63f9 100644 --- a/resources/views/livewire/project/index.blade.php +++ b/resources/views/livewire/project/index.blade.php @@ -13,7 +13,7 @@ @forelse ($projects as $project)
+ onclick="gotoProject('{{ $project->uuid }}','{{ $project->default_environment() }}')">
{{ $project->name }}
{{ $project->description }}