networks
This commit is contained in:
13
app/Enums/NetworkType.php
Normal file
13
app/Enums/NetworkType.php
Normal 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
37
app/Models/Network.php
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user