'int', 'status' => 'int', 'int' => 'int', 'object' => 'array', ]; protected $fillable = [ 'identifier', 'slug', 'referenz', 'action', 'object', 'full_text', 'text', 'int', 'status', 'type', ]; protected static $types = [ 'object' => 'Object', 'full_text' => 'Full Text', 'text' => 'Text', 'int' => 'Zahl', 'bool' => 'Bool', ]; public function sluggable(): array { return [ 'slug' => [ 'source' => 'name', ], ]; } public static function getContentBySlug($slug) { $content = self::whereSlug(trim($slug))->first(); if ($content) { switch ($content->type) { case 'object': return $content->object; break; case 'full_text': return $content->full_text; break; case 'text': return $content->text; break; case 'int': return $content->int; break; case 'bool': return $content->int === 1 ? true : false; break; } } return false; } public static function setContentBySlug($slug, $value, $type = 'full_text') { $content = self::whereSlug(trim($slug))->first(); if (! $content) { $content = self::create([ 'slug' => $slug, 'type' => $type, ]); } $content->type = $type; switch ($content->type) { case 'object': $content->object = is_array($value) ? $value : ($value ?: null); break; case 'full_text': $content->full_text = $value ? $value : null; break; case 'text': $content->text = $value ? $value : null; break; case 'int': $content->int = (int) $value; break; case 'bool': $content->int = $value ? 1 : 0; break; } $content->save(); return $content; } }