Level 11
Right now, the solution I came up with.
// In controller
$results = Category::all()->sortBy('name')->groupBy(function ($item, $key) {
return substr($item['name'], 0, 1);
});
// In view - total count
{{ count($results->collapse()->all()) }}
// In view -individual count
@foreach($results as $key => $result)
<h4>{{ ucfirst($key) }} - {{ count($result) }}</h4>
// ul and other stuff ...
@endforeach
Let me know if there any better way to do it.