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