'array', 'trans_title' => 'array', 'trans_copy' => 'array', 'icons' => 'array', 'trans_description' => 'array', 'trans_usage' => 'array', 'trans_ingredients' => 'array' ]; use Sluggable; use SoftDeletes; protected $dates = ['deleted_at']; protected $fillable = [ 'name', 'title', 'copy', 'price', 'price_ek', 'tax', 'price_old', 'contents', 'number', 'icons', 'description', 'usage', 'ingredients', 'pos', 'amount', 'active' ]; public function sluggable() { return [ 'slug' => [ 'source' => 'name' ] ]; } public function attributes(){ return $this->hasMany('App\Models\ProductAttribute', 'product_id', 'id'); } public function categories(){ return $this->hasMany('App\Models\ProductCategory', 'product_id', 'id'); } public function images(){ return $this->hasMany('App\Models\ProductImage', 'product_id', 'id'); } public function _format_number($value){ return preg_replace("/[^0-9,]/", "", $value); } public function setPriceAttribute( $value ) { $value = $this->_format_number($value); $this->attributes['price'] = floatval(str_replace(',', '.', $value)); } public function setPriceEkAttribute( $value ) { $value = $this->_format_number($value); $this->attributes['price_ek'] = floatval(str_replace(',', '.', $value)); } public function setTaxAttribute( $value ) { $value = $this->_format_number($value); $this->attributes['tax'] = floatval(str_replace(',', '.', $value)); } public function setPriceOldAttribute( $value ) { $value = $this->_format_number($value); $this->attributes['price_old'] = floatval(str_replace(',', '.', $value)); } public function getFormattedPrice() { if(\App::getLocale() == "en"){ return number_format($this->attributes['price'], 2, '.', ','); } return number_format($this->attributes['price'], 2, ',', '.'); } public function getFormattedPriceEk() { if(\App::getLocale() == "en"){ return number_format($this->attributes['price_ek'], 2, '.', ','); } return number_format($this->attributes['price_ek'], 2, ',', '.'); } public function getFormattedTax() { if(\App::getLocale() == "en"){ return number_format($this->attributes['tax'], 2, '.', ','); } return number_format($this->attributes['tax'], 2, ',', '.'); } public function getFormattedPriceOld() { if(\App::getLocale() == "en"){ return number_format($this->attributes['price_old'], 2, '.', ','); } return number_format($this->attributes['price_old'], 2, ',', '.'); } 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, ', '); } }