Refactor default_environment method to handle projects with 0 environments

This commit is contained in:
Andras Bacsai 2024-06-24 18:41:44 +02:00
parent 4869c388b2
commit 99354f0d7d
3 changed files with 9 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -23,7 +23,7 @@
<div class="grid grid-cols-1 gap-2 xl:grid-cols-2">
@foreach ($projects as $project)
<div class="gap-2 border border-transparent cursor-pointer box group"
onclick="gotoProject('{{ $project->uuid }}','{{ $project->default_environment()?->name }}')">
onclick="gotoProject('{{ $project->uuid }}','{{ $project->default_environment() }}')">
<div class="flex flex-1 mx-6">
<div class="flex flex-col justify-center flex-1">
<div class="box-title">{{ $project->name }}</div>

View File

@ -13,7 +13,7 @@
@forelse ($projects as $project)
<div class="box group" x-data x-on:click="goto('{{ $project->uuid }}')">
<div class="flex flex-col justify-center flex-1 mx-6"
onclick="gotoProject('{{ $project->uuid }}','{{ $project->default_environment()?->name }}')">
onclick="gotoProject('{{ $project->uuid }}','{{ $project->default_environment() }}')">
<div class="box-title">{{ $project->name }}</div>
<div class="box-description ">
{{ $project->description }}</div>