<div>
@php
                    $grouped = sidebar_categories()->groupBy(fn($cat) => $cat->parent_category->name ?? 'Others');
                    @endphp

                    <div class="categories-widget widget-item">
                        <h3 class="widget-title">Categories</h3>

                        @foreach ($grouped as $parentName => $categories)
                        <h6 class="mt-3"><strong>{{ $parentName }}</strong></h6>
                        <ul class="ms-3">
                            @foreach ($categories as $item)
                            <li>
                                <a href="{{ route('category_post', $item->slug) }}">
                                    {{ $item->name }} <span>({{ $item->posts_count }})</span>
                                </a>
                            </li>
                            @endforeach
                        </ul>
                        @endforeach
                    </div>
</div>