@foreach($allMark as $mark)
<li class="mark-list-li">
<a href="/{{$mark->url}}/"><span class="name-li">{{$mark->name}}</span> ({{$mark->rus_name}})</a><span class="gray-color"> - {{$mark->models_count}} моделей</span>
</li>
@endforeach
$allMark = $allMark->groupBy(function ($item, $key) {
return strtoupper(mb_substr($item->name, 0, 1));
});
@foreach($allMark as $key => $marks)
{{ $key }}
@for@foreach($marks as $mark)
{{ $mark->name }}
@endforeach
@endforeach
@php
// вариант с массивами
$abcMarks = [];
$oldFirst = null;
foreach ($makes as $make) {
$i = $oldFirst == mb_substr($make->name, 0, 1) ? $oldFirst : mb_substr($make->name, 0, 1);
$abcMarks[$i][] = $make->name;
}
// или вариант с коллекциями
$abcMarks = $makes->groupBy(function ($item, $key) {
return strtoupper(mb_substr($item->name, 0, 1));
});
@endphp
<div class="marks">
@foreach($abcMarks as $key => $marks)
<div class="marks__group">
<div class="marks__title"><strong>{{ $key }}</strong></div>
<div class="marks__list">
@foreach($marks as $mark)
<div class="marks__item">
{{ $mark }}
</div>
@endforeach
</div>
</div>
@endforeach
</div>