'Text (190 Zeichen)', 'full_text' => 'Full Text (50K Zeichen)', 'integer' => 'Zahl (10 Stellen)', 'decimal' => 'Kommazahl (10,2 Stellen)', ]; protected $connection = 'mysql_stern'; protected $table = 'c_m_s_contents'; protected $fillable = [ 'name', 'field', 'text', 'full_text', 'integer', 'decimal', ]; public function sluggable() { return [ 'slug' => [ 'source' => 'name' ] ]; } public static function getFieldsOptions($setKey = false){ $options = self::$fields; $ret = ""; foreach ($options as $key => $option){ $attr = ($key == $setKey) ? 'selected="selected"' : ''; $ret .= '\n'; } return $ret; } public function getFieldName(){ return isset(self::$fields[$this->field]) ? self::$fields[$this->field] : ''; } public function getPreviewContent(){ $content = $this->{$this->field}; if(strlen($content) > 40){ return substr($content, 0, 40)." ..."; } return $content; } public function _format_number($value){ return preg_replace("/[^0-9,]/", "", $value); } public function setDecimalAttribute($value) { $value = $this->_format_number($value); $value = substr($value, -13); $this->attributes['decimal'] = floatval(str_replace(',', '.', $value)); } public function getDecimalAttribute() { if(isset($this->attributes['decimal'])){ // 2 = decimal places | '.' = decimal seperator | ',' = thousand seperator return number_format(($this->attributes['decimal']), 2, ',', '.'); } return ""; } public function setIntegerAttribute($value) { $value = $this->_format_number($value); $value = substr($value, -10); $this->attributes['integer'] = intval($value); } }