moving to provider stored in database
This commit is contained in:
@@ -4,7 +4,7 @@ namespace App\Enums;
|
||||
|
||||
use App\Enums\Concerns\Arrayable;
|
||||
|
||||
enum ServerProvider: string
|
||||
enum ProviderType: string
|
||||
{
|
||||
use Arrayable;
|
||||
|
||||
@@ -72,7 +72,7 @@ class ServerController extends Controller
|
||||
|
||||
$server = $organisation->servers()->create([
|
||||
'name' => $createdServer->name,
|
||||
'provider' => ServerProvider::tryFrom($request->provider),
|
||||
// 'provider' => ServerProvider::tryFrom($request->provider), // @todo
|
||||
'provider_id' => $createdServer->id,
|
||||
'ipv4' => $createdServer->ipv4,
|
||||
'ipv6' => $createdServer->ipv6,
|
||||
|
||||
@@ -16,7 +16,6 @@ class Network extends Model
|
||||
{
|
||||
return [
|
||||
'type' => NetworkType::class,
|
||||
'provider' => ServerProvider::class,
|
||||
];
|
||||
}
|
||||
|
||||
@@ -34,4 +33,9 @@ class Network extends Model
|
||||
{
|
||||
return $this->belongsTo(Organisation::class);
|
||||
}
|
||||
|
||||
public function provider(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Provider::class);
|
||||
}
|
||||
}
|
||||
|
||||
30
app/Models/Provider.php
Normal file
30
app/Models/Provider.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\ProviderType;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class Provider extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'token' => 'encrypted',
|
||||
'type' => ProviderType::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function networks(): HasMany
|
||||
{
|
||||
return $this->hasMany(Network::class);
|
||||
}
|
||||
|
||||
public function servers(): HasMany
|
||||
{
|
||||
return $this->hasMany(Server::class);
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,6 @@ class Server extends Model
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'provider' => ServerProvider::class,
|
||||
'status' => ServerStatus::class,
|
||||
];
|
||||
}
|
||||
@@ -66,6 +65,11 @@ class Server extends Model
|
||||
return $this->hasMany(FirewallRule::class);
|
||||
}
|
||||
|
||||
public function provider(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Provider::class);
|
||||
}
|
||||
|
||||
public function sshClient(string $user = 'root'): Ssh
|
||||
{
|
||||
return Ssh::create($user, $this->ipv4)
|
||||
|
||||
Reference in New Issue
Block a user