@php
$popularHsCodes = \App\Models\CalculationLog::selectRaw('
CASE
WHEN JSON_VALID(input) THEN JSON_UNQUOTE(JSON_EXTRACT(input, "$.hs_code"))
ELSE NULL
END as hs_code,
COUNT(*) as count
')
->whereNotNull('input')
->groupBy('hs_code')
->orderByDesc('count')
->take(5)
->get();
@endphp
@if($popularHsCodes->count() > 0)
@foreach($popularHsCodes as $item)
@if($item->hs_code)
@php
$hsCode = \App\Models\HsCode::where('hs_code', $item->hs_code)->first();
@endphp
{{ $item->hs_code }}
{{ $hsCode->description ?? 'Unknown' }}
{{ $item->count }} calculations
@endif
@endforeach
@else
No HS code data available.
@endif