cascade()->forHumans(); } } // 获取系统设置 if (! function_exists('sysConfig')) { function sysConfig(?string $key = null, ?string $default = null): array|string|int|null { return $key ? config("settings.$key", $default) : config('settings'); } } // Array values and indexes clean if (! function_exists('array_clean')) { function array_clean(array &$array): array { foreach ($array as $key => &$value) { if (is_array($value)) { $value = array_clean($value); } if (empty($value)) { unset($array[$key]); } } return $array; } } // string url safe sanitize if (! function_exists('string_urlsafe')) { function string_urlsafe(string $string, bool $force_lowercase = true, bool $anal = false): string { $clean = preg_replace('/[~`!@#$%^&*()_=+\[\]{}\\|;:"\'<>,.?\/]/', '_', strip_tags($string)); $clean = preg_replace('/\s+/', '-', $clean); $clean = ($anal) ? preg_replace('/[^a-zA-Z0-9]/', '', $clean) : $clean; if ($force_lowercase) { $clean = function_exists('mb_strtolower') ? mb_strtolower($clean, 'UTF-8') : strtolower($clean); } return $clean; } } if (! function_exists('localized_date')) { function localized_date($date): string { if (! $date) { return ''; } $carbon = Carbon::parse($date); $locale = app()->getLocale(); $carbon->setLocale($locale); // 获取原始字符串表示 $dateStr = is_string($date) ? $date : $date->format('Y-m-d H:i:s'); // 使用正则检测精度 if (preg_match('/(\d{4}-\d{2}-\d{2}) (\d{2}):(\d{2}):(\d{2})/', $dateStr, $matches)) { $hours = (int) $matches[2]; $minutes = (int) $matches[3]; $seconds = (int) $matches[4]; if ($seconds > 0) { return $carbon->isoFormat('LL LTS'); // 显示完整时间 } if ($minutes > 0 || $hours > 0) { return $carbon->isoFormat('LL LT'); // 显示到分钟 } } return $carbon->isoFormat('LL'); // 只显示日期 } }