laravel - foreach in foreach in if blade php
Get the solution ↓↓↓@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
Answer
Solution:
Simply use the loop variable.
@foreach ($exampleProjects as $k => $exampleProject)
<div class="carousel-item{{ $loop->first ? ' active' : '' }}">
</div>
@endforeach
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: object not found by the @paramconverter annotation.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.