*/ use HasFactory; protected $guarded = []; protected function casts(): array { return [ 'status' => ServerStatus::class, ]; } public static function boot(): void { parent::boot(); } public function network(): BelongsTo { return $this->belongsTo(Network::class, 'network'); } public function organisation(): BelongsTo { return $this->belongsTo(Organisation::class); } public function services(): HasMany { return $this->hasMany(Service::class); } public function instances(): HasMany { return $this->hasMany(Instance::class); } public function applications(): HasManyThrough { return $this->hasManyThrough(Application::class, Instance::class); } public function firewallRules(): HasMany { return $this->hasMany(FirewallRule::class); } public function provider(): BelongsTo { return $this->belongsTo(Provider::class); } public function serviceDeployments(): HasManyThrough { return $this->hasManyThrough( Deployment::class, Service::class, 'server_id', 'target_id', )->where('target_type', (new Service)->getMorphClass()); } public function applicationDeployments(): HasManyThrough { return $this->hasManyThrough( Deployment::class, Application::class, 'server_id', 'target_id', )->where('target_type', (new Application)->getMorphClass()); } public function sshClient(string $user = 'root'): Ssh { return Ssh::create($user, $this->ipv4) ->usePrivateKey(storage_path('app/private/ssh/id_ed25519')) ->disableStrictHostKeyChecking(); } }