initial commit
This commit is contained in:
58
app/Models/VmDevice.php
Normal file
58
app/Models/VmDevice.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class VmDevice extends Model
|
||||
{
|
||||
public const TYPE_DISK = 'disk';
|
||||
|
||||
public const TYPE_NETWORK = 'network';
|
||||
|
||||
public const TYPE_USB = 'usb';
|
||||
|
||||
public const TYPE_PCI = 'pci';
|
||||
|
||||
public static function types(): array
|
||||
{
|
||||
return [
|
||||
self::TYPE_DISK => 'Zusätzliche Festplatte',
|
||||
self::TYPE_NETWORK => 'Netzwerk-Interface',
|
||||
self::TYPE_USB => 'USB-Gerät',
|
||||
self::TYPE_PCI => 'PCI Passthrough',
|
||||
];
|
||||
}
|
||||
|
||||
public static function typesFor(?\App\Models\User $user = null): array
|
||||
{
|
||||
$types = self::types();
|
||||
if ($user && ! $user->isAdmin()) {
|
||||
return array_intersect_key($types, array_flip([self::TYPE_DISK, self::TYPE_NETWORK]));
|
||||
}
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
protected $fillable = [
|
||||
'customer_id',
|
||||
'type',
|
||||
'slot',
|
||||
'config',
|
||||
'sort_order',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'config' => 'array',
|
||||
'sort_order' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function vm(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Customer::class, 'customer_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user