diff --git a/app/Forms/CommonForm.php b/app/Forms/CommonForm.php index f8c1ff0..5ce8b0a 100644 --- a/app/Forms/CommonForm.php +++ b/app/Forms/CommonForm.php @@ -210,35 +210,29 @@ abstract class CommonForm } } catch (\TypeError $e) { // TypeError(예: trim(null) 등) 발생 시 범인(field) 찾기 시도 - $culpritField = "알 수 없음"; - $culpritValue = "null"; - - foreach ($dynamicRules as $f => $r) { - if (str_contains($r['rules'], 'trim')) { - // 중첩 필드(.*)와 일반 필드 구분하여 null 체크 - if (str_contains($f, '.*')) { - $parentKey = str_replace('.*', '', $f); - if (isset($formDatas[$parentKey]) && is_array($formDatas[$parentKey])) { - foreach ($formDatas[$parentKey] as $k => $v) { - if ($v === null) { - $culpritField = "{$parentKey}.{$k} ({$r['label']})"; - break 2; - } - } - } - } else { - if (!isset($formDatas[$f]) || $formDatas[$f] === null) { - $culpritField = "{$f} ({$r['label']})"; - break; - } + $nullFields = []; + $findNulls = function ($data, $path = '') use (&$findNulls, &$nullFields) { + foreach ($data as $k => $v) { + $curr = $path ? "{$path}.{$k}" : $k; + if (is_array($v)) { + $findNulls($v, $curr); + } elseif ($v === null) { + $nullFields[] = $curr; } } - } + }; + $findNulls($formDatas); + + $culpritInfo = count($nullFields) > 0 ? implode(', ', $nullFields) : "데이터 내 null 없음 (시스템 내 필터 등에 의해 발생 가능성)"; $errorMsg = $e->getMessage(); - // "trim(): Argument #1 ($string) must be of type string, null given" 문구에서 Argument #1을 필드명으로 교체 - $errorMsg = str_replace("Argument #1 (\$string)", "데이터(필드: {$culpritField}, 값: {$culpritValue})", $errorMsg); - throw new RuntimeException("검증 도중 타입 오류 발생: " . $errorMsg); + // 상세 정보 포함 + $debugInfo = "\n--- [상세 디버깅 정보] ---\n"; + $debugInfo .= "범인 의심 필드(null값): " . $culpritInfo . "\n"; + $debugInfo .= "전송된 데이터(전체): " . json_encode($formDatas, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n"; + $debugInfo .= "규칙 정보: " . json_encode($dynamicRules, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT) . "\n"; + + throw new RuntimeException("검증 도중 타입 오류 발생: {$errorMsg}{$debugInfo}"); } // 검증 성공 시 추가 로직 없이 종료