$childrens * @property-read int|null $childrens_count * @property-read \App\Models\Attribute|null $parent * @method static \Illuminate\Database\Eloquent\Builder|AttributeType newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|AttributeType newQuery() * @method static \Illuminate\Database\Eloquent\Builder|AttributeType query() * @method static \Illuminate\Database\Eloquent\Builder|AttributeType whereActive($value) * @method static \Illuminate\Database\Eloquent\Builder|AttributeType whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|AttributeType whereDescription($value) * @method static \Illuminate\Database\Eloquent\Builder|AttributeType whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|AttributeType whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|AttributeType whereParentId($value) * @method static \Illuminate\Database\Eloquent\Builder|AttributeType wherePos($value) * @method static \Illuminate\Database\Eloquent\Builder|AttributeType whereSlug($value) * @method static \Illuminate\Database\Eloquent\Builder|AttributeType whereTransName($value) * @method static \Illuminate\Database\Eloquent\Builder|AttributeType whereUpdatedAt($value) * @mixin \Eloquent */ class AttributeType extends Model { protected $table = 'attribute_types'; protected $casts = [ 'parent_id' => 'int', 'pos' => 'int', 'active' => 'bool', 'trans_name' => 'array' ]; protected $fillable = [ 'parent_id', 'name', 'description', 'trans_name', 'pos', 'active', 'slug' ]; 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 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, ', '); } }