coolify/app/Models/Application.php

69 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace App\Models;
2023-03-30 09:47:04 +02:00
use Illuminate\Database\Eloquent\Casts\Attribute;
use Spatie\Activitylog\Models\Activity;
class Application extends BaseModel
{
protected static function booted()
{
static::created(function ($application) {
ApplicationSetting::create([
'application_id' => $application->id,
]);
});
}
2023-03-27 18:14:33 +02:00
public function environment()
{
2023-03-27 18:14:33 +02:00
return $this->belongsTo(Environment::class);
}
2023-03-28 15:47:37 +02:00
public function settings()
{
return $this->hasOne(ApplicationSetting::class);
}
2023-03-27 14:31:42 +02:00
public function destination()
{
return $this->morphTo();
}
2023-03-28 12:09:34 +02:00
public function source()
{
return $this->morphTo();
}
2023-04-03 13:37:53 +02:00
public function persistentStorages()
{
return $this->morphMany(LocalPersistentVolume::class, 'resource');
}
2023-03-30 09:47:04 +02:00
public function portsMappings(): Attribute
{
return Attribute::make(
get: fn (string|null $portsMappings) =>
is_null($portsMappings)
? []
: explode(',', $portsMappings)
);
}
public function portsExposes(): Attribute
{
return Attribute::make(
get: fn (string|null $portsExposes) =>
is_null($portsExposes)
? []
: explode(',', $portsExposes)
);
}
public function deployments()
{
return Activity::where('subject_id', $this->id)->where('properties->deployment_uuid', '!=', null)->orderBy('created_at', 'desc')->get();
}
public function get_deployment(string $deployment_uuid)
2023-03-28 15:47:37 +02:00
{
return Activity::where('subject_id', $this->id)->where('properties->deployment_uuid', '=', $deployment_uuid)->first();
2023-03-28 15:47:37 +02:00
}
}