coolify/app/Models/ServiceDatabase.php

40 lines
921 B
PHP
Raw Normal View History

2023-09-20 15:42:41 +02:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class ServiceDatabase extends BaseModel
{
use HasFactory;
protected $guarded = [];
2023-11-06 18:04:18 +01:00
protected static function booted()
{
static::deleting(function ($service) {
$service->persistentStorages()->delete();
$service->fileStorages()->delete();
});
}
2023-09-22 11:23:49 +02:00
public function type()
{
return 'service';
}
2023-09-22 12:08:51 +02:00
public function service()
{
return $this->belongsTo(Service::class);
}
2023-09-22 11:23:49 +02:00
public function persistentStorages()
{
return $this->morphMany(LocalPersistentVolume::class, 'resource');
}
public function fileStorages()
{
return $this->morphMany(LocalFileVolume::class, 'resource');
}
2023-10-02 18:02:32 +02:00
public function getFilesFromServer(bool $isInit = false)
{
2023-10-02 18:02:32 +02:00
getFilesystemVolumesFromServer($this, $isInit);
}
2023-09-20 15:42:41 +02:00
}