$device->uuid ??= (string) Str::uuid()); } protected function casts(): array { return ['is_active' => 'boolean', 'remove_legacy_users_on_activation' => 'boolean', 'connection_ports' => 'array', 'device_facts' => 'array', 'last_seen_at' => 'datetime', 'activated_at' => 'datetime', 'base_synced_at' => 'datetime', 'base_sync_attempted_at' => 'datetime', 'latitude' => 'decimal:7', 'longitude' => 'decimal:7']; } public function portFor(string $protocol): ?int { $port = $this->connection_ports[$protocol] ?? ($this->connection_type === $protocol ? $this->management_port : null); return $port ? (int) $port : null; } public function hasConnection(string $protocol): bool { return $this->portFor($protocol) !== null; } public function vendor() { return $this->belongsTo(DeviceVendor::class, 'device_vendor_id'); } public function type() { return $this->belongsTo(DeviceType::class, 'device_type_id'); } public function model() { return $this->belongsTo(DeviceModel::class, 'device_model_id'); } public function credentials() { return $this->hasMany(DeviceCredential::class); } public function creator() { return $this->belongsTo(User::class, 'created_by'); } public function userAssignments() { return $this->hasMany(DeviceUserAssignment::class); } }