Files
librenms-librenms/app/Models/StateIndex.php
Tony Murray 7d450345df Fix sensor state translations (#16393)
* Fix sensor state translations

* Fix up lint/style

* Set state_index_id

* Apply fixes from StyleCI

* Wrong call

* just use a loop

* Wrong id column

* Missing fillable

* Handle sensors missing state translations

* Before making a state index

* Can't map to a state index if it doesn't exist

* Apply fixes from StyleCI

* ies5000 overflowing tinyint

* Accept state translations directly add that in the translation

* handle duplicate state names, but with different case (skip no way to work there)

* Apply fixes from StyleCI

* Fix type stuffs

---------

Co-authored-by: Tony Murray <murrant@users.noreply.github.com>
2024-09-15 02:13:11 +02:00

29 lines
803 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
class StateIndex extends Model
{
use HasFactory;
public $timestamps = false;
protected $table = 'state_indexes';
protected $fillable = ['state_name'];
protected $primaryKey = 'state_index_id';
public function sensors(): HasManyThrough
{
return $this->hasManyThrough(Sensor::class, SensorToStateIndex::class, 'state_index_id', 'sensor_id', 'state_index_id', 'sensor_id');
}
public function translations(): HasMany
{
return $this->hasMany(StateTranslation::class, 'state_index_id', 'state_index_id');
}
}