diff --git a/app/Models/Sensor.php b/app/Models/Sensor.php index 2626d9c6f4..5952f3291d 100644 --- a/app/Models/Sensor.php +++ b/app/Models/Sensor.php @@ -3,6 +3,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\MorphMany; class Sensor extends DeviceRelatedModel @@ -78,4 +79,9 @@ class Sensor extends DeviceRelatedModel { return $this->morphMany(Eventlog::class, 'events', 'type', 'reference'); } + + public function translations(): BelongsToMany + { + return $this->belongsToMany(StateTranslation::class, 'sensors_to_state_indexes', 'sensor_id', 'state_index_id'); + } } diff --git a/app/Models/StateTranslation.php b/app/Models/StateTranslation.php new file mode 100644 index 0000000000..0be7de8d2e --- /dev/null +++ b/app/Models/StateTranslation.php @@ -0,0 +1,34 @@ +. + * + * @package LibreNMS + * @link http://librenms.org + * @copyright 2021 Tony Murray + * @author Tony Murray + */ + +namespace App\Models; + +use Illuminate\Database\Eloquent\Model; + +class StateTranslation extends Model +{ + public $timestamps = false; + protected $primaryKey = 'state_index_id'; +}