where('autoload', true) ->orderBy('id') ->get(['config_key', 'config_value', 'value_type']); foreach ($configs as $row) { $key = (string) ($row->config_key ?? ''); if ($key === '') { continue; } $type = (string) ($row->value_type ?? 'string'); $raw = $row->config_value; $value = match ($type) { 'boolean' => in_array(strtolower((string) $raw), ['1', 'true', 'yes', 'on'], true), 'number' => is_numeric($raw) ? (float) $raw : 0.0, 'json' => (function () use ($raw) { $decoded = json_decode((string) ($raw ?? ''), true); return json_last_error() === JSON_ERROR_NONE ? $decoded : null; })(), default => $raw, }; // JSON 解析失败时直接跳过(不影响系统启动) if ($type === 'json' && $value === null) { continue; } // 注意:使用 dot key 注入到 config(),例如:saasshop.amounts.tolerance config([$key => $value]); } } catch (\Throwable $e) { // 不阻断启动:治理配置加载失败时,回退到 config/*.php 默认值 return; } } }