Files
Network-MGMT/app/Models/NetworkDeviceEvent.php
T

57 lines
1.5 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class NetworkDeviceEvent extends Model
{
protected $fillable = [
'device_id', 'scan_id', 'event_type', 'old_value',
'new_value', 'description', 'documented',
'documented_by', 'documented_at',
];
protected $casts = [
'documented' => 'boolean',
'documented_at' => 'datetime',
];
public function device(): BelongsTo
{
return $this->belongsTo(NetworkDevice::class, 'device_id');
}
public function documentedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'documented_by');
}
public function getEventLabelAttribute(): string
{
return match($this->event_type) {
'new_device' => 'Neues Gerät',
'ip_changed' => 'IP-Adresse geändert',
'came_online' => 'Gerät online',
'went_offline' => 'Gerät offline',
'manual_note' => 'Manuelle Notiz',
'label_changed' => 'Bezeichnung geändert',
default => $this->event_type,
};
}
public function getEventColorAttribute(): string
{
return match($this->event_type) {
'new_device' => 'blue',
'ip_changed' => 'yellow',
'came_online' => 'green',
'went_offline' => 'red',
'manual_note' => 'purple',
'label_changed' => 'gray',
default => 'gray',
};
}
}