{{-- Key-Value 테이블 표시용 Partial --}} @php /** * JSON 데이터를 Key-Value 테이블로 렌더링 * 중첩 배열/객체는 재귀적으로 표시 */ if (!function_exists('renderJsonValue')) { function renderJsonValue($value, $depth = 0) { if (is_null($value)) { return 'null'; } if (is_bool($value)) { return $value ? 'true' : 'false'; } if (is_numeric($value)) { return '' . e($value) . ''; } if (is_string($value)) { return '' . e($value) . ''; } if (is_array($value)) { // 순차 배열인지 연관 배열인지 확인 if (empty($value)) { return '[]'; } if (array_keys($value) === range(0, count($value) - 1)) { // 순차 배열: 인라인으로 표시 if (count($value) <= 5 && !array_filter($value, 'is_array')) { // 단순 배열이면 인라인 표시 $items = array_map(fn($v) => is_string($v) ? e($v) : e(json_encode($v, JSON_UNESCAPED_UNICODE)), $value); return '[' . implode(', ', $items) . ']'; } // 복잡한 배열은 리스트로 표시 $html = '
'; foreach ($value as $idx => $item) { $html .= '
'; $html .= '[' . $idx . ']'; $html .= '
' . renderJsonValue($item, $depth + 1) . '
'; $html .= '
'; } $html .= '
'; return $html; } else { // 연관 배열: 중첩 테이블로 표시 $html = '
'; foreach ($value as $k => $v) { $html .= '
'; $html .= '' . e($k) . ':'; $html .= '
' . renderJsonValue($v, $depth + 1) . '
'; $html .= '
'; } $html .= '
'; return $html; } } return '' . e(gettype($value)) . ''; } } @endphp @if(is_array($data) && !empty($data)) @foreach($data as $key => $value) @endforeach
Key Value
{{ $key }} {!! renderJsonValue($value) !!}
@else 데이터 없음 @endif