@php $diff = $getState() ?? ['summary' => [], 'added' => [], 'removed' => [], 'changed' => []]; $summary = $diff['summary'] ?? []; $groupByBlock = static function (array $items): array { $groups = []; foreach ($items as $path => $value) { if (! is_string($path) || $path === '') { continue; } $parts = explode(' > ', $path, 2); if (count($parts) === 2) { [$group, $label] = $parts; } else { $group = 'Other'; $label = $path; } $groups[$group][$label] = $value; } ksort($groups); return $groups; }; $stringify = static function (mixed $value): string { if ($value === null) { return '—'; } if (is_bool($value)) { return $value ? 'Enabled' : 'Disabled'; } if (is_scalar($value)) { return (string) $value; } return json_encode($value, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) ?: ''; }; $isExpandable = static function (mixed $value): bool { if (is_array($value)) { return true; } return is_string($value) && strlen($value) > 160; }; @endphp
{{ (int) ($summary['added'] ?? 0) }} added {{ (int) ($summary['removed'] ?? 0) }} removed {{ (int) ($summary['changed'] ?? 0) }} changed
@foreach (['changed' => ['label' => 'Changed', 'collapsed' => false], 'added' => ['label' => 'Added', 'collapsed' => true], 'removed' => ['label' => 'Removed', 'collapsed' => true]] as $key => $meta) @php $items = $diff[$key] ?? []; $groups = $groupByBlock(is_array($items) ? $items : []); @endphp @if ($groups !== [])
@foreach ($groups as $group => $groupItems)
{{ $group }}
{{ count($groupItems) }}
@foreach ($groupItems as $name => $value)
@if ($key === 'changed' && is_array($value) && array_key_exists('from', $value) && array_key_exists('to', $value)) @php $from = $value['from']; $to = $value['to']; $fromText = $stringify($from); $toText = $stringify($to); @endphp
{{ (string) $name }}
From @if ($isExpandable($from))
View
{{ $fromText }}
@else
{{ $fromText }}
@endif
To @if ($isExpandable($to))
View
{{ $toText }}
@else
{{ $toText }}
@endif
@else @php $text = $stringify($value); @endphp
{{ (string) $name }}
@if ($isExpandable($value))
View
{{ $text }}
@else
{{ $text }}
@endif
@endif
@endforeach
@endforeach
@endif @endforeach