This commit is contained in:
2025-04-06 18:30:25 +01:00
parent 2d15f87f42
commit 319520c650
5 changed files with 91 additions and 0 deletions

13
app/Enums/NetworkType.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
namespace App\Enums;
use App\Enums\Concerns\Arrayable;
enum NetworkType: string
{
use Arrayable;
case EXTERNAL = 'external'; // managed by provider
case INTERNAL = 'internal'; // managed by keystone
}

37
app/Models/Network.php Normal file
View File

@@ -0,0 +1,37 @@
<?php
namespace App\Models;
use App\Enums\NetworkType;
use App\Enums\ServerProvider;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Network extends Model
{
protected $guarded = [];
protected function casts(): array
{
return [
'type' => NetworkType::class,
'provider' => ServerProvider::class,
];
}
public function internalServers(): HasMany
{
return $this->hasMany(Server::class, 'internal_network_id');
}
public function externalServers(): HasMany
{
return $this->hasMany(Server::class, 'external_network_id');
}
public function organisation(): BelongsTo
{
return $this->belongsTo(Organisation::class);
}
}

View File

@@ -25,6 +25,16 @@ class Server extends Model
];
}
public function externalNetwork(): BelongsTo
{
return $this->belongsTo(Network::class, 'external_network_id');
}
public function internalNetwork(): BelongsTo
{
return $this->belongsTo(Network::class, 'internal_network_id');
}
public function organisation(): BelongsTo
{
return $this->belongsTo(Organisation::class);