'boolean', ]; /** * 获取配置值(根据类型转换) * * @return mixed */ public function getTypedValue() { $value = $this->config_value ?? $this->default_value; if ($value === null) { return null; } switch ($this->config_type) { case 'integer': return (int) $value; case 'float': return (float) $value; case 'boolean': return in_array(strtolower($value), ['1', 'true', 'yes', 'on']); case 'json': return json_decode($value, true); case 'string': default: return (string) $value; } } /** * 设置配置值(根据类型转换) * * @param mixed $value * @return void */ public function setTypedValue($value): void { switch ($this->config_type) { case 'json': $this->config_value = json_encode($value); break; case 'boolean': $this->config_value = $value ? '1' : '0'; break; default: $this->config_value = (string) $value; break; } } /** * 获取配置类型的中文名称 * * @return string */ public function getConfigTypeNameAttribute(): string { $types = [ 'string' => '字符串', 'integer' => '整数', 'float' => '浮点数', 'boolean' => '布尔值', 'json' => 'JSON对象', ]; return $types[$this->config_type] ?? '未知'; } /** * 获取启用状态的中文名称 * * @return string */ public function getIsActiveNameAttribute(): string { return $this->is_active ? '启用' : '禁用'; } }