$translations * @property-read int|null $translations_count * @method static \Illuminate\Database\Eloquent\Builder|UserLevel whereTransName($value) * @mixin \Eloquent */ class UserLevel extends Model { protected $table = 'user_levels'; protected $fillable = [ 'next_id', 'name', 'margin', 'margin_shop', 'qual_kp', 'qual_pp', 'growth_bonus', 'pr_line_1', 'pr_line_2', 'pr_line_3', 'pr_line_4', 'pr_line_5', 'pr_line_6', 'pr_line_7', 'pr_line_8', 'paylines', 'pos', 'active', 'default', ]; public function next_user_level() { return $this->belongsTo('App\Models\UserLevel', 'next_id', 'id'); } public function translations() { return $this->hasMany(TransUserLevel::class, 'user_level_id'); } public function getNextUserLevels(){ //$ret = [0=>'Keinen']; $ret = UserLevel::where('active', true)->where('id', '!=', $this->id)->orderBy('pos', 'asc')->get()->pluck('name', 'id')->toArray(); return array_add($ret, 0, '-> Keinen Karriere Level'); } public function setPosAttribute($value){ $this->attributes['pos'] = is_numeric($value) ? $value : null; } public function setGrowthBonusAttribute($value) { $this->attributes['growth_bonus'] = $value !== null ? Util::reFormatNumber($value) : null; } public function getFormattedGrowthBonus() { return isset($this->attributes['growth_bonus']) ? Util::formatNumber($this->attributes['growth_bonus'],1) : ""; } public function getFormattedMargin() { return isset($this->attributes['margin']) ? Util::formatNumber($this->attributes['margin'], 1) : ""; } public function getFormattedMarginShop() { return isset($this->attributes['margin_shop']) ? Util::formatNumber($this->attributes['margin_shop'], 1) : ""; } public function getLang($key) { $lang = \App::getLocale(); if ($lang == 'de') { return $this->{$key}; } $trans = $this->getTrans($key, $lang); return $trans != '' ? $trans : $this->{$key}; } public function getTrans($key, $lang) { $trans = $this->translations->where('language','=', $lang)->where('key', $key)->first(); return $trans ? $trans->value : ''; } }