'array', 'trans_headline' => 'array', 'show_on' => 'array']; protected $fillable = [ 'parent_id', 'name', 'headline', 'pos', 'active', 'show_on' ]; public function sluggable() { return [ 'slug' => [ 'source' => 'name' ] ]; } public function parent() { return $this->belongsTo('App\Models\Category', 'parent_id'); } public function childrens() { return $this->hasMany('App\Models\Category', 'parent_id', 'id'); } public function product_categories() { return $this->hasMany('App\Models\ProductCategory', 'category_id', 'id'); } public function iq_image() { return $this->belongsTo('App\Models\IqImage', 'headline_image_id'); } public function setPosAttribute($value){ $this->attributes['pos'] = is_numeric($value) ? $value : null; } 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]; } return ""; } public function getTranNames() { $ret = ""; foreach ((array) $this->trans_name as $value){ $ret .= $value.', '; } return rtrim($ret, ', '); } public function getTranHeadlines() { $ret = ""; foreach ((array) $this->trans_headline as $value){ $ret .= $value.', '; } return rtrim($ret, ', '); } public function getShowOnTypes(){ $ret = []; if($this->show_on && is_array($this->show_on)){ foreach($this->show_on as $show){ $ret[] = isset(Type::$showONs[$show]) ? Type::$showONs[$show] : '-'; } } return $ret; } }