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
|
public function organisation(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Organisation::class);
|
return $this->belongsTo(Organisation::class);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Network;
|
||||||
use App\Models\Organisation;
|
use App\Models\Organisation;
|
||||||
use Illuminate\Database\Migrations\Migration;
|
use Illuminate\Database\Migrations\Migration;
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
@@ -12,6 +13,8 @@ return new class extends Migration
|
|||||||
Schema::create('servers', function (Blueprint $table) {
|
Schema::create('servers', function (Blueprint $table) {
|
||||||
$table->id();
|
$table->id();
|
||||||
$table->foreignIdFor(Organisation::class);
|
$table->foreignIdFor(Organisation::class);
|
||||||
|
$table->foreignIdFor(Network::class, 'external_network_id');
|
||||||
|
$table->foreignIdFor(Network::class, 'internal_network_id');
|
||||||
$table->string('name');
|
$table->string('name');
|
||||||
$table->string('provider');
|
$table->string('provider');
|
||||||
$table->string('provider_id');
|
$table->string('provider_id');
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\Organisation;
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('networks', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignIdFor(Organisation::class);
|
||||||
|
$table->string('type');
|
||||||
|
$table->string('provider')->nullable();
|
||||||
|
$table->string('provider_id')->nullable();
|
||||||
|
$table->string('name');
|
||||||
|
$table->string('ip_range');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('networks');
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user