feat: Netzwerk-Segmentverwaltung, Dashboard, globale Suche v0.6.0
This commit is contained in:
@@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
class NetworkScan extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'subnet', 'source', 'scanner', 'total_hosts',
|
||||
'segment_id', 'subnet', 'source', 'scanner', 'total_hosts',
|
||||
'online_hosts', 'new_devices', 'changed_devices',
|
||||
'notes', 'created_by',
|
||||
];
|
||||
@@ -27,4 +27,9 @@ class NetworkScan extends Model
|
||||
{
|
||||
return $this->belongsTo(User::class, 'created_by');
|
||||
}
|
||||
|
||||
public function segment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(NetworkSegment::class, 'segment_id');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user