Files
Virtnet.bond/extensions/Servers/Proxmox/Models/Server.php

89 lines
1.9 KiB
PHP

<?php
namespace Paymenter\Extensions\Servers\Proxmox\Models;
use App\Models\Service;
use Illuminate\Database\Eloquent\Model;
class Server extends Model
{
protected $table = 'ext_proxmox_servers';
protected $fillable = [
'user_id',
'node_id',
'os_id',
'service_id',
'vm_id',
'primary_ipv4',
'primary_ipv6',
'status',
'hostname',
'password',
'user_set_icon',
'user_set_icon_color',
'user_set_icon_prefix',
'tag1',
'tag1color',
'tag2',
'tag2color',
'tag3',
'tag3color',
];
/**
* Get tags as an array of objects
*/
public function getTagsAttribute(): array
{
$tags = [];
if (!empty($this->tag1)) {
$tags[] = ['text' => $this->tag1, 'color' => $this->tag1color ?? '#3498db'];
}
if (!empty($this->tag2)) {
$tags[] = ['text' => $this->tag2, 'color' => $this->tag2color ?? '#3498db'];
}
if (!empty($this->tag3)) {
$tags[] = ['text' => $this->tag3, 'color' => $this->tag3color ?? '#3498db'];
}
return $tags;
}
public function node()
{
return $this->belongsTo(Node::class);
}
public function os()
{
return $this->belongsTo(OS::class);
}
public function ipAddresses()
{
return $this->hasMany(IPAddress::class);
}
public function service()
{
return $this->belongsTo(Service::class);
}
public function primaryIpv4()
{
return $this->belongsTo(IPAddress::class, 'primary_ipv4');
}
public function primaryIpv6()
{
return $this->belongsTo(IPAddress::class, 'primary_ipv6');
}
public function statistics()
{
return $this->hasMany(ServerStatistics::class);
}
}