feat: Netzwerk-Segmentverwaltung, Dashboard, globale Suche v0.6.0

This commit is contained in:
2026-07-01 18:46:49 +02:00
parent 402537805d
commit 9fa20af87a
17 changed files with 1006 additions and 60 deletions
+59
View File
@@ -0,0 +1,59 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
class NetworkSegment extends Model
{
protected $fillable = [
'name', 'subnet', 'vlan_id', 'active', 'description', 'created_by',
];
protected $casts = [
'active' => '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');
}
}