coolify/app/Models/LocalPersistentVolume.php

60 lines
1.2 KiB
PHP
Raw Normal View History

2023-04-03 13:37:53 +02:00
<?php
namespace App\Models;
2023-05-05 12:08:38 +02:00
use Illuminate\Database\Eloquent\Casts\Attribute;
2023-06-15 13:28:16 +02:00
use Illuminate\Database\Eloquent\Model;
2023-05-05 12:08:38 +02:00
use Illuminate\Support\Str;
2023-06-15 13:28:16 +02:00
class LocalPersistentVolume extends Model
2023-04-03 13:37:53 +02:00
{
2023-08-07 22:14:21 +02:00
protected $guarded = [];
2023-04-03 13:37:53 +02:00
public function application()
{
return $this->morphTo('resource');
2023-04-03 13:37:53 +02:00
}
2024-06-10 22:43:34 +02:00
2023-09-20 15:42:41 +02:00
public function service()
{
return $this->morphTo('resource');
}
2024-06-10 22:43:34 +02:00
public function database()
{
return $this->morphTo('resource');
2023-09-20 15:42:41 +02:00
}
2024-06-10 22:43:34 +02:00
2023-08-07 22:14:21 +02:00
public function standalone_postgresql()
{
return $this->morphTo('resource');
2023-08-07 22:14:21 +02:00
}
2023-05-05 12:08:38 +02:00
protected function name(): Attribute
{
return Attribute::make(
2023-08-11 20:48:52 +02:00
set: fn (string $value) => Str::of($value)->trim()->value,
2023-05-05 12:08:38 +02:00
);
}
2023-05-05 12:08:38 +02:00
protected function mountPath(): Attribute
{
return Attribute::make(
2023-08-11 20:48:52 +02:00
set: fn (string $value) => Str::of($value)->trim()->start('/')->value
2023-05-05 12:08:38 +02:00
);
}
2023-05-05 12:08:38 +02:00
protected function hostPath(): Attribute
{
return Attribute::make(
2024-06-10 22:43:34 +02:00
set: function (?string $value) {
2023-05-05 12:08:38 +02:00
if ($value) {
return Str::of($value)->trim()->start('/')->value;
} else {
return $value;
}
}
);
}
2023-04-03 13:37:53 +02:00
}