feat: Netzwerk-Modul v0.5.0 – Import, Geräte-Tracking, Ereignislog
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class NetworkDevice extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'mac_address', 'current_ip', 'hostname', 'mac_vendor',
|
||||
'status', 'netbios_name', 'ttl', 'ports', 'notes',
|
||||
'label', 'first_seen_at', 'last_seen_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'first_seen_at' => 'datetime',
|
||||
'last_seen_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function hosts(): HasMany
|
||||
{
|
||||
return $this->hasMany(NetworkHost::class, 'device_id');
|
||||
}
|
||||
|
||||
public function events(): HasMany
|
||||
{
|
||||
return $this->hasMany(NetworkDeviceEvent::class, 'device_id')->latest();
|
||||
}
|
||||
|
||||
public function getDisplayNameAttribute(): string
|
||||
{
|
||||
return $this->label
|
||||
?? $this->hostname
|
||||
?? $this->current_ip
|
||||
?? $this->mac_address;
|
||||
}
|
||||
|
||||
public function getStatusColorAttribute(): string
|
||||
{
|
||||
return match($this->status) {
|
||||
'online' => 'green',
|
||||
'offline' => 'red',
|
||||
default => 'gray',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user