mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Type hint model relations (#12673)
This commit is contained in:
@@ -26,6 +26,8 @@ namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use LibreNMS\Enum\AlertState;
|
||||
|
||||
class Alert extends Model
|
||||
@@ -56,17 +58,17 @@ class Alert extends Model
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function device()
|
||||
public function device(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Device::class, 'device_id');
|
||||
}
|
||||
|
||||
public function rule()
|
||||
public function rule(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\AlertRule::class, 'rule_id', 'id');
|
||||
}
|
||||
|
||||
public function users()
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\User::class, 'devices_perms', 'device_id', 'user_id');
|
||||
}
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use LibreNMS\Enum\AlertState;
|
||||
|
||||
class AlertRule extends BaseModel
|
||||
@@ -78,12 +80,12 @@ class AlertRule extends BaseModel
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function alerts()
|
||||
public function alerts(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Alert::class, 'rule_id');
|
||||
}
|
||||
|
||||
public function devices()
|
||||
public function devices(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Device::class, 'alert_device_map', 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
+69
-59
@@ -6,6 +6,11 @@ use Fico7489\Laravel\Pivot\Traits\PivotEventTrait;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphToMany;
|
||||
use Illuminate\Database\Query\JoinClause;
|
||||
use Illuminate\Support\Str;
|
||||
use LibreNMS\Exceptions\InvalidIpException;
|
||||
@@ -17,6 +22,11 @@ use LibreNMS\Util\Time;
|
||||
use LibreNMS\Util\Url;
|
||||
use Permissions;
|
||||
|
||||
/**
|
||||
* @property-read int|null $ports_count
|
||||
* @property-read int|null $sensors_count
|
||||
* @property-read int|null $wirelessSensors_count
|
||||
*/
|
||||
class Device extends BaseModel
|
||||
{
|
||||
use PivotEventTrait, HasFactory;
|
||||
@@ -525,298 +535,298 @@ class Device extends BaseModel
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function accessPoints()
|
||||
public function accessPoints(): HasMany
|
||||
{
|
||||
return $this->hasMany(AccessPoint::class, 'device_id');
|
||||
}
|
||||
|
||||
public function alerts()
|
||||
public function alerts(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Alert::class, 'device_id');
|
||||
}
|
||||
|
||||
public function attribs()
|
||||
public function attribs(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\DeviceAttrib::class, 'device_id');
|
||||
}
|
||||
|
||||
public function alertSchedules()
|
||||
public function alertSchedules(): MorphToMany
|
||||
{
|
||||
return $this->morphToMany(\App\Models\AlertSchedule::class, 'alert_schedulable', 'alert_schedulables', 'schedule_id', 'schedule_id');
|
||||
}
|
||||
|
||||
public function applications()
|
||||
public function applications(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Application::class, 'device_id');
|
||||
}
|
||||
|
||||
public function bgppeers()
|
||||
public function bgppeers(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\BgpPeer::class, 'device_id');
|
||||
}
|
||||
|
||||
public function cefSwitching()
|
||||
public function cefSwitching(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\CefSwitching::class, 'device_id');
|
||||
}
|
||||
|
||||
public function children()
|
||||
public function children(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(self::class, 'device_relationships', 'parent_device_id', 'child_device_id');
|
||||
}
|
||||
|
||||
public function components()
|
||||
public function components(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Component::class, 'device_id');
|
||||
}
|
||||
|
||||
public function hostResources()
|
||||
public function hostResources(): HasMany
|
||||
{
|
||||
return $this->hasMany(HrDevice::class, 'device_id');
|
||||
}
|
||||
|
||||
public function entityPhysical()
|
||||
public function entityPhysical(): HasMany
|
||||
{
|
||||
return $this->hasMany(EntPhysical::class, 'device_id');
|
||||
}
|
||||
|
||||
public function eventlogs()
|
||||
public function eventlogs(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Eventlog::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function graphs()
|
||||
public function graphs(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\DeviceGraph::class, 'device_id');
|
||||
}
|
||||
|
||||
public function groups()
|
||||
public function groups(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\DeviceGroup::class, 'device_group_device', 'device_id', 'device_group_id');
|
||||
}
|
||||
|
||||
public function ipsecTunnels()
|
||||
public function ipsecTunnels(): HasMany
|
||||
{
|
||||
return $this->hasMany(IpsecTunnel::class, 'device_id');
|
||||
}
|
||||
|
||||
public function ipv4()
|
||||
public function ipv4(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(\App\Models\Ipv4Address::class, \App\Models\Port::class, 'device_id', 'port_id', 'device_id', 'port_id');
|
||||
}
|
||||
|
||||
public function ipv6()
|
||||
public function ipv6(): HasManyThrough
|
||||
{
|
||||
return $this->hasManyThrough(\App\Models\Ipv6Address::class, \App\Models\Port::class, 'device_id', 'port_id', 'device_id', 'port_id');
|
||||
}
|
||||
|
||||
public function location()
|
||||
public function location(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Location::class, 'location_id', 'id');
|
||||
}
|
||||
|
||||
public function mefInfo()
|
||||
public function mefInfo(): HasMany
|
||||
{
|
||||
return $this->hasMany(MefInfo::class, 'device_id');
|
||||
}
|
||||
|
||||
public function muninPlugins()
|
||||
public function muninPlugins(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\MuninPlugin::class, 'device_id');
|
||||
}
|
||||
|
||||
public function ospfInstances()
|
||||
public function ospfInstances(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\OspfInstance::class, 'device_id');
|
||||
}
|
||||
|
||||
public function ospfNbrs()
|
||||
public function ospfNbrs(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\OspfNbr::class, 'device_id');
|
||||
}
|
||||
|
||||
public function ospfPorts()
|
||||
public function ospfPorts(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\OspfPort::class, 'device_id');
|
||||
}
|
||||
|
||||
public function netscalerVservers()
|
||||
public function netscalerVservers(): HasMany
|
||||
{
|
||||
return $this->hasMany(NetscalerVserver::class, 'device_id');
|
||||
}
|
||||
|
||||
public function packages()
|
||||
public function packages(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Package::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function parents()
|
||||
public function parents(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(self::class, 'device_relationships', 'child_device_id', 'parent_device_id');
|
||||
}
|
||||
|
||||
public function perf()
|
||||
public function perf(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\DevicePerf::class, 'device_id');
|
||||
}
|
||||
|
||||
public function ports()
|
||||
public function ports(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Port::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function portsFdb()
|
||||
public function portsFdb(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\PortsFdb::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function portsNac()
|
||||
public function portsNac(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\PortsNac::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function processors()
|
||||
public function processors(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Processor::class, 'device_id');
|
||||
}
|
||||
|
||||
public function routes()
|
||||
public function routes(): HasMany
|
||||
{
|
||||
return $this->hasMany(Route::class, 'device_id');
|
||||
}
|
||||
|
||||
public function rules()
|
||||
public function rules(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\AlertRule::class, 'alert_device_map', 'device_id', 'rule_id');
|
||||
}
|
||||
|
||||
public function sensors()
|
||||
public function sensors(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Sensor::class, 'device_id');
|
||||
}
|
||||
|
||||
public function serviceTemplates()
|
||||
public function serviceTemplates(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\ServiceTemplate::class, 'service_templates_device', 'device_id', 'service_template_id');
|
||||
}
|
||||
|
||||
public function services()
|
||||
public function services(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Service::class, 'device_id');
|
||||
}
|
||||
|
||||
public function storage()
|
||||
public function storage(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Storage::class, 'device_id');
|
||||
}
|
||||
|
||||
public function stpInstances()
|
||||
public function stpInstances(): HasMany
|
||||
{
|
||||
return $this->hasMany(Stp::class, 'device_id');
|
||||
}
|
||||
|
||||
public function mempools()
|
||||
public function mempools(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Mempool::class, 'device_id');
|
||||
}
|
||||
|
||||
public function mplsLsps()
|
||||
public function mplsLsps(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\MplsLsp::class, 'device_id');
|
||||
}
|
||||
|
||||
public function mplsLspPaths()
|
||||
public function mplsLspPaths(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\MplsLspPath::class, 'device_id');
|
||||
}
|
||||
|
||||
public function mplsSdps()
|
||||
public function mplsSdps(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\MplsSdp::class, 'device_id');
|
||||
}
|
||||
|
||||
public function mplsServices()
|
||||
public function mplsServices(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\MplsService::class, 'device_id');
|
||||
}
|
||||
|
||||
public function mplsSaps()
|
||||
public function mplsSaps(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\MplsSap::class, 'device_id');
|
||||
}
|
||||
|
||||
public function mplsSdpBinds()
|
||||
public function mplsSdpBinds(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\MplsSdpBind::class, 'device_id');
|
||||
}
|
||||
|
||||
public function mplsTunnelArHops()
|
||||
public function mplsTunnelArHops(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\MplsTunnelArHop::class, 'device_id');
|
||||
}
|
||||
|
||||
public function mplsTunnelCHops()
|
||||
public function mplsTunnelCHops(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\MplsTunnelCHop::class, 'device_id');
|
||||
}
|
||||
|
||||
public function printerSupplies()
|
||||
public function printerSupplies(): HasMany
|
||||
{
|
||||
return $this->hasMany(PrinterSupply::class, 'device_id');
|
||||
}
|
||||
|
||||
public function pseudowires()
|
||||
public function pseudowires(): HasMany
|
||||
{
|
||||
return $this->hasMany(Pseudowire::class, 'device_id');
|
||||
}
|
||||
|
||||
public function rServers()
|
||||
public function rServers(): HasMany
|
||||
{
|
||||
return $this->hasMany(LoadbalancerRserver::class, 'device_id');
|
||||
}
|
||||
|
||||
public function slas()
|
||||
public function slas(): HasMany
|
||||
{
|
||||
return $this->hasMany(Sla::class, 'device_id');
|
||||
}
|
||||
|
||||
public function syslogs()
|
||||
public function syslogs(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Syslog::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function users()
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
// FIXME does not include global read
|
||||
return $this->belongsToMany(\App\Models\User::class, 'devices_perms', 'device_id', 'user_id');
|
||||
}
|
||||
|
||||
public function vminfo()
|
||||
public function vminfo(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Vminfo::class, 'device_id');
|
||||
}
|
||||
|
||||
public function vlans()
|
||||
public function vlans(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Vlan::class, 'device_id');
|
||||
}
|
||||
|
||||
public function vrfLites()
|
||||
public function vrfLites(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\VrfLite::class, 'device_id');
|
||||
}
|
||||
|
||||
public function vrfs()
|
||||
public function vrfs(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Vrf::class, 'device_id');
|
||||
}
|
||||
|
||||
public function vServers()
|
||||
public function vServers(): HasMany
|
||||
{
|
||||
return $this->hasMany(LoadbalancerVserver::class, 'device_id');
|
||||
}
|
||||
|
||||
public function wirelessSensors()
|
||||
public function wirelessSensors(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\WirelessSensor::class, 'device_id');
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use LibreNMS\Alerting\QueryBuilderFluentParser;
|
||||
use Log;
|
||||
use Permissions;
|
||||
@@ -162,22 +163,22 @@ class DeviceGroup extends BaseModel
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function devices()
|
||||
public function devices(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Device::class, 'device_group_device', 'device_group_id', 'device_id');
|
||||
}
|
||||
|
||||
public function services()
|
||||
public function services(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Service::class, 'device_group_device', 'device_group_id', 'device_id');
|
||||
}
|
||||
|
||||
public function users()
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\User::class, 'devices_group_perms', 'device_group_id', 'user_id');
|
||||
}
|
||||
|
||||
public function serviceTemplates()
|
||||
public function serviceTemplates(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\ServiceTemplate::class, 'service_templates_device_group', 'device_group_id', 'service_template_id');
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class DeviceRelatedModel extends BaseModel
|
||||
{
|
||||
// ---- Query Scopes ----
|
||||
@@ -44,7 +46,7 @@ class DeviceRelatedModel extends BaseModel
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function device()
|
||||
public function device(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Device::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ use Illuminate\Contracts\Container\BindingResolutionException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use LibreNMS\Util\Dns;
|
||||
|
||||
class Location extends Model
|
||||
@@ -162,7 +163,7 @@ class Location extends Model
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function devices()
|
||||
public function devices(): HasMany
|
||||
{
|
||||
return $this->hasMany(\App\Models\Device::class, 'location_id');
|
||||
}
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
abstract class PortRelatedModel extends BaseModel
|
||||
{
|
||||
// ---- Query scopes ----
|
||||
@@ -35,7 +37,7 @@ abstract class PortRelatedModel extends BaseModel
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function port()
|
||||
public function port(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Port::class, 'port_id', 'port_id');
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class PortsFdb extends PortRelatedModel
|
||||
{
|
||||
protected $table = 'ports_fdb';
|
||||
@@ -10,12 +12,12 @@ class PortsFdb extends PortRelatedModel
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function device()
|
||||
public function device(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Device::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function vlan()
|
||||
public function vlan(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Vlan::class, 'vlan_id', 'vlan_id');
|
||||
}
|
||||
|
||||
@@ -39,11 +39,6 @@ class Route extends DeviceRelatedModel
|
||||
public $timestamps = true;
|
||||
|
||||
// ---- Define Relationships ----
|
||||
public function device()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Device::class, 'device_id', 'device_id');
|
||||
}
|
||||
|
||||
public function port()
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Port::class, 'port_id', 'port_id');
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use LibreNMS\Alerting\QueryBuilderFluentParser;
|
||||
use Log;
|
||||
|
||||
@@ -197,17 +198,17 @@ class ServiceTemplate extends BaseModel
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function devices()
|
||||
public function devices(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Device::class, 'service_templates_device', 'service_template_id', 'device_id');
|
||||
}
|
||||
|
||||
public function services()
|
||||
public function services(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\Service::class, 'service_templates_device', 'service_template_id', 'device_id');
|
||||
}
|
||||
|
||||
public function groups()
|
||||
public function groups(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\DeviceGroup::class, 'service_templates_device_group', 'service_template_id', 'device_group_id');
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
|
||||
class UserWidget extends Model
|
||||
{
|
||||
@@ -14,17 +16,17 @@ class UserWidget extends Model
|
||||
|
||||
// ---- Define Relationships ----
|
||||
|
||||
public function user()
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\User::class, 'user_id');
|
||||
}
|
||||
|
||||
public function widget()
|
||||
public function widget(): HasOne
|
||||
{
|
||||
return $this->hasOne(\App\Models\Widget::class, 'widget_id');
|
||||
}
|
||||
|
||||
public function dashboard()
|
||||
public function dashboard(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(\App\Models\Dashboard::class, 'dashboard_id');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user