diff --git a/LibreNMS/Util/Url.php b/LibreNMS/Util/Url.php
index bc1f13ea54..af7271f1e9 100644
--- a/LibreNMS/Util/Url.php
+++ b/LibreNMS/Util/Url.php
@@ -139,7 +139,7 @@ class Url
$text = $label;
}
- $content = '
' . addslashes(htmlentities($port->device->displayName() . ' - ' . $label)) . '
';
+ $content = '' . addslashes(htmlentities(optional($port->device)->displayName() . ' - ' . $label)) . '
';
if ($description = $port->getDescription()) {
$content .= addslashes(htmlentities($description)) . '
';
}
@@ -230,7 +230,7 @@ class Url
*/
public static function deviceUrl($device, $vars = [])
{
- $routeParams = [is_numeric($device) ? $device : $device->device_id];
+ $routeParams = [($device instanceof Device) ? $device->device_id : (int) $device];
if (isset($vars['tab'])) {
$routeParams[] = $vars['tab'];
unset($vars['tab']);
diff --git a/app/Http/Controllers/PaginatedAjaxController.php b/app/Http/Controllers/PaginatedAjaxController.php
index 1a91bcbd63..4d9454bc05 100644
--- a/app/Http/Controllers/PaginatedAjaxController.php
+++ b/app/Http/Controllers/PaginatedAjaxController.php
@@ -146,9 +146,18 @@ abstract class PaginatedAjaxController extends Controller
protected function filter($request, $query, $fields)
{
foreach ($fields as $target => $field) {
- if (is_callable($field)) {
- $field($query, $request->get($target));
- } elseif (($value = $request->get($field)) !== null) {
+ $callable = is_callable($field);
+ $value = $request->get($callable ? $target : $field);
+
+ // unfiltered field
+ if ($value === null) {
+ continue;
+ }
+
+ // apply the filter
+ if ($callable) {
+ $field($query, $value);
+ } else {
$value = $this->adjustFilterValue($field, $value);
if (is_string($target)) {
$query->where($target, $value);
diff --git a/app/Http/Controllers/Table/PortsController.php b/app/Http/Controllers/Table/PortsController.php
index 499f8e4cf2..4010753377 100644
--- a/app/Http/Controllers/Table/PortsController.php
+++ b/app/Http/Controllers/Table/PortsController.php
@@ -155,7 +155,7 @@ class PortsController extends TableController
'status' => $status,
'device' => Url::deviceLink($port->device),
'port' => Url::portLink($port),
- 'secondsIfLastChange' => ceil($port->device->uptime - ($port->ifLastChange / 100)),
+ 'secondsIfLastChange' => ceil(optional($port->device)->uptime - ($port->ifLastChange / 100)),
'ifConnectorPresent' => ($port->ifConnectorPresent == 'true') ? 'yes' : 'no',
'ifSpeed' => $port->ifSpeed,
'ifMtu' => $port->ifMtu,
diff --git a/app/Models/Port.php b/app/Models/Port.php
index d123d87e74..9b4e9aa7b5 100644
--- a/app/Models/Port.php
+++ b/app/Models/Port.php
@@ -61,7 +61,7 @@ class Port extends DeviceRelatedModel
*/
public function getLabel()
{
- $os = $this->device->os;
+ $os = optional($this->device)->os;
if (\LibreNMS\Config::getOsSetting($os, 'ifname')) {
$label = $this->ifName;