'int', 'pos' => 'int', 'active' => 'bool', 'trans_name' => 'array', ]; protected $fillable = [ 'parent_id', 'attribute_type_id', 'name', 'value', 'trans_name', 'pos', 'active', 'slug' ]; public function attribute_type() { return $this->belongsTo(AttributeType::class, 'attribute_type_id'); } public function parent() { return $this->belongsTo(Attribute::class, 'parent_id'); } public function childrens() { return $this->hasMany(Attribute::class, 'parent_id', 'id'); } public function setPosAttribute($value){ $this->attributes['pos'] = is_numeric($value) ? $value : null; } public function getFormattedValue() { // return isset($this->attributes['value']) ? Util::formatNumber($this->attributes['value']) : ""; } public function getLang($key) { $lang = \App::getLocale(); if ($lang == 'de') { return $this->{$key}; } $trans = $this->getTrans($key, $lang); if (!$trans || $trans == '') { return $this->{$key}; } return $trans; } public function getTrans($key, $lang) { $key = 'trans_' . $key; if (!empty($this->{$key}[$lang])) { return $this->{$key}[$lang]; } } public function getTranNames() { $ret = ""; foreach ((array) $this->trans_name as $value){ $ret .= $value.', '; } return rtrim($ret, ', '); } }