65 lines
1.5 KiB
PHP
65 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\SchedulerMode;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
|
use Illuminate\Support\Str;
|
|
|
|
class Environment extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (Environment $environment): void {
|
|
$environment->uuid ??= (string) Str::uuid();
|
|
});
|
|
}
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'scheduler_enabled' => 'boolean',
|
|
'scheduler_mode' => SchedulerMode::class,
|
|
'build_config' => 'array',
|
|
];
|
|
}
|
|
|
|
public function application(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Application::class);
|
|
}
|
|
|
|
public function services(): HasMany
|
|
{
|
|
return $this->hasMany(Service::class);
|
|
}
|
|
|
|
public function attachments(): HasMany
|
|
{
|
|
return $this->hasMany(EnvironmentAttachment::class);
|
|
}
|
|
|
|
public function variables(): HasMany
|
|
{
|
|
return $this->hasMany(EnvironmentVariable::class);
|
|
}
|
|
|
|
public function buildArtifacts(): HasMany
|
|
{
|
|
return $this->hasMany(BuildArtifact::class);
|
|
}
|
|
|
|
public function operations(): MorphMany
|
|
{
|
|
return $this->morphMany(Operation::class, 'target');
|
|
}
|
|
}
|