Новые автомобили в наличии
@php
$marks = \JustWeCMS\Modules\Auto\Entities\Mark::where('active', 1)->orderBy('position')->
with(['model' => function($query) {
$query->where('active', 1);
$query->has('body');
}])->
with(['model.body' => function($query) {
$query->where('active', 1);
$query->orderBy('position');
$query->filter();
}])
->get();
@endphp
@foreach($marks as $mark)
@php
$bodyCount = 0;
$mark->model->map(function ($model) use(&$bodyCount) {
$bodyCount += $model->body->count();
});
@endphp
@if( $bodyCount !== 0 )
@foreach($mark->model as $model)
@foreach($model->body as $bodyItem)
@include(get_view('catalog-car-item', [
'bodyItem' => $bodyItem
]))
@endforeach
@endforeach
@endif
@endforeach