2023-04-03 11:37:53 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2023-05-05 10:08:38 +00:00
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
2023-06-15 11:28:16 +00:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2023-05-05 10:08:38 +00:00
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
2023-06-15 11:28:16 +00:00
|
|
|
class LocalPersistentVolume extends Model
|
2023-04-03 11:37:53 +00:00
|
|
|
{
|
2023-05-05 10:08:38 +00:00
|
|
|
protected $fillable = [
|
|
|
|
'name',
|
|
|
|
'mount_path',
|
|
|
|
'host_path',
|
|
|
|
'container_id',
|
|
|
|
'resource_id',
|
|
|
|
'resource_type',
|
|
|
|
];
|
2023-04-03 11:37:53 +00:00
|
|
|
public function application()
|
|
|
|
{
|
|
|
|
return $this->morphTo();
|
|
|
|
}
|
2023-05-05 10:08:38 +00:00
|
|
|
protected function name(): Attribute
|
|
|
|
{
|
|
|
|
return Attribute::make(
|
|
|
|
set: fn (string $value) => Str::of($value)->trim()->value,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
protected function mountPath(): Attribute
|
|
|
|
{
|
|
|
|
return Attribute::make(
|
|
|
|
set: fn (string $value) => Str::of($value)->trim()->start('/')->value
|
|
|
|
);
|
|
|
|
}
|
|
|
|
protected function hostPath(): Attribute
|
|
|
|
{
|
|
|
|
return Attribute::make(
|
|
|
|
set: function (string|null $value) {
|
|
|
|
if ($value) {
|
|
|
|
return Str::of($value)->trim()->start('/')->value;
|
|
|
|
} else {
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
2023-04-03 11:37:53 +00:00
|
|
|
}
|