Laravel 5.4检查块是否是第一块

时间:2017-09-24 13:14:10

标签: php laravel-5 chunking

我正在尝试设置条件检查块是否是第一批块。

任何人都知道如何检查块ID或类似内容,例如:

@foreach($item->chunk(3) as $item_chunk
    @if(chunk is first chunk)
        <div class="carousel-item active">
    @else
        <div class="carousel-item">
    @endif

    @foreach($item_chunk as $item)
        {{-- Do something --}}
    @endforeach 
@endforeach

如果有人知道检查分块列表是否是第一个的方法,请欣赏它。

2 个答案:

答案 0 :(得分:1)

您可以使用$loop variable检查循环。

@foreach($item->chunk(3) as $item_chunk)
    @if($loop->first)
        <div class="carousel-item active">
    @else
        <div class="carousel-item">
    @endif

    @foreach($item_chunk as $item)
        {{-- Do something --}}
    @endforeach 
@endforeach

答案 1 :(得分:0)

对于滑块

            <div class="carousel-inner">
              @foreach($item_hr as $count => $valuetopproducts)
                <div class="item {!! $count == 0 ? 'active' : '' !!}">
                      <a href="{{ url('asset_details')}}/{{$valuetopproducts->assetid}}"><img src="{{Storage::url('wp/thumbnail')}}/{{$valuetopproducts->imagename}}" class="img-responsive" alt="{!! \Illuminate\Support\Str::words($valuetopproducts->assetname, 10,'...')  !!}"></a>
                </div>
              @endforeach
            </div>