'boolean', 'vlan_id' => 'integer', ]; public function createdBy(): BelongsTo { return $this->belongsTo(User::class, 'created_by'); } public function scans(): HasMany { return $this->hasMany(NetworkScan::class, 'segment_id'); } public function latestScan(): HasMany { return $this->hasMany(NetworkScan::class, 'segment_id')->latestOfMany(); } /** Alle Hosts dieses Segments (über Scans) */ public function hosts(): HasManyThrough { return $this->hasManyThrough(NetworkHost::class, NetworkScan::class, 'segment_id', 'scan_id'); } /** Anzahl online-Hosts im letzten Scan */ public function getOnlineCountAttribute(): int { return $this->scans()->latest()->first()?->online_hosts ?? 0; } /** Anzahl Geräte gesamt im letzten Scan */ public function getTotalCountAttribute(): int { return $this->scans()->latest()->first()?->total_hosts ?? 0; } /** Letzter Scan-Zeitpunkt */ public function getLastScannedAtAttribute(): ?string { return $this->scans()->latest()->first()?->created_at?->format('d.m.Y H:i'); } }