Maxi Albeldas
Maxi Albeldas

Reputation: 11

foreach in foreach in if blade php

@foreach ($capacityGroups as $capacityGroupFather)

@foreach ($exampleProjects as $k => $exampleProject)

@foreach ($exampleProject->capacityGroups as $j => $exampleCapacity)

@if ($exampleCapacity->id == $capacityGroupFather->id)

Only the first result of the loop

<div class="carousel-item active">

The rest of the loop

<div class="carousel-item">

We have the example Projects collection, each of which has capacityGroups. I need to bring all the example Projects for each capacity Group. But the first of each goes into a special div (carousel-item active) and the rest of each goes into (carousel-item) how can I fix this problem

Upvotes: 1

Views: 84

Answers (1)

IGP
IGP

Reputation: 15909

Simply use the loop variable.

@foreach ($exampleProjects as $k => $exampleProject)
    <div class="carousel-item{{ $loop->first ? ' active' : '' }}">
    </div>
@endforeach

Upvotes: 3

Related Questions