coolify/app/Models/Environment.php

91 lines
2.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
2023-04-25 14:43:35 +02:00
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
class Environment extends Model
{
2023-10-24 10:43:34 +02:00
protected $guarded = [];
public function isEmpty()
2023-04-25 14:43:35 +02:00
{
2023-10-19 13:32:03 +02:00
return $this->applications()->count() == 0 &&
$this->redis()->count() == 0 &&
$this->postgresqls()->count() == 0 &&
$this->mysqls()->count() == 0 &&
$this->mariadbs()->count() == 0 &&
2023-10-19 13:32:03 +02:00
$this->mongodbs()->count() == 0 &&
$this->services()->count() == 0;
2023-08-07 18:46:40 +02:00
}
2024-01-23 17:13:23 +01:00
public function environment_variables() {
return $this->hasMany(SharedEnvironmentVariable::class);
}
public function applications()
{
2023-03-27 18:14:33 +02:00
return $this->hasMany(Application::class);
}
2023-08-07 18:46:40 +02:00
public function postgresqls()
{
2023-08-07 22:14:21 +02:00
return $this->hasMany(StandalonePostgresql::class);
}
2023-10-12 17:18:33 +02:00
public function redis()
{
return $this->hasMany(StandaloneRedis::class);
}
2023-10-19 13:32:03 +02:00
public function mongodbs()
{
return $this->hasMany(StandaloneMongodb::class);
}
2023-10-24 14:31:28 +02:00
public function mysqls()
{
return $this->hasMany(StandaloneMysql::class);
}
public function mariadbs()
{
return $this->hasMany(StandaloneMariadb::class);
}
2024-04-10 15:00:46 +02:00
public function keydbs()
{
return $this->hasMany(StandaloneKeydb::class);
}
public function dragonflies()
{
return $this->hasMany(StandaloneDragonfly::class);
}
public function clickhouses()
{
return $this->hasMany(StandaloneClickhouse::class);
}
public function databases()
{
2023-10-12 17:18:33 +02:00
$postgresqls = $this->postgresqls;
$redis = $this->redis;
2023-10-19 13:32:03 +02:00
$mongodbs = $this->mongodbs;
2023-10-24 14:31:28 +02:00
$mysqls = $this->mysqls;
$mariadbs = $this->mariadbs;
2024-04-10 15:00:46 +02:00
$keydbs = $this->keydbs;
$dragonflies = $this->dragonflies;
$clickhouses = $this->clickhouses;
return $postgresqls->concat($redis)->concat($mongodbs)->concat($mysqls)->concat($mariadbs)->concat($keydbs)->concat($dragonflies)->concat($clickhouses);
}
public function project()
{
return $this->belongsTo(Project::class);
}
2023-03-28 08:28:03 +02:00
public function services()
{
return $this->hasMany(Service::class);
}
protected function name(): Attribute
{
return Attribute::make(
2023-08-11 20:48:52 +02:00
set: fn (string $value) => strtolower($value),
);
}
2023-08-07 22:14:21 +02:00
}