55 lines
1.3 KiB
PHP
55 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\RepositoryType;
|
|
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 Application extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (Application $application): void {
|
|
$application->uuid ??= (string) Str::uuid();
|
|
});
|
|
}
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'repository_type' => RepositoryType::class,
|
|
'deploy_key_private' => 'encrypted',
|
|
'deploy_key_installed_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function organisation(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Organisation::class);
|
|
}
|
|
|
|
public function sourceProvider(): BelongsTo
|
|
{
|
|
return $this->belongsTo(SourceProvider::class);
|
|
}
|
|
|
|
public function environments(): HasMany
|
|
{
|
|
return $this->hasMany(Environment::class);
|
|
}
|
|
|
|
public function operations(): MorphMany
|
|
{
|
|
return $this->morphMany(Operation::class, 'target');
|
|
}
|
|
}
|