there is a different structure to show projects
Project 1 and 2 are in the same Project 3 is in a different
Project 4 and 5 are in the same Project 6 is in a different
it goes on like this
div will open if $i == 1
If $i == 2 the div will be closed
If $i == 3 the div will be opened and closed
my code
@foreach($projects as $project)
@if($loop->iteration % 3 === 0 || $loop->first || $loop->iteration % 2 === 0)
<div class="project"> @endif
<img src="{{ Voyager::image($project->image) }}" alt="{{ $project->title }}">
@if($loop->iteration % 3 === 0 || $loop->last || $loop->iteration % 2 === 0) </div>
@endif
@endforeach
my code result
<div class="project">
<img src="project1.jpg" alt="">
<div class="project">
<img src="project2.jpg" alt="">
</div>
<div class="project">
<img src="project3.jpg" alt="">
</div>
<div class="project">
<img src="project4.jpg" alt="">
</div>
<img src="project5.jpg" alt="">
<div class="project">
<img src="project6.jpg" alt="">
</div>
<img src="project7.jpg" alt="">
<div class="project">
<img src="project8.jpg" alt="">
</div>
<div class="project">
<img src="project9.jpg" alt="">
</div>
the result i want
<div class="project">
<img src="project1.jpg" alt="">
<img src="project2.jpg" alt="">
</div>
<div class="project">
<img src="project3.jpg" alt="">
</div>
<div class="project">
<img src="project4.jpg" alt="">
<img src="project5.jpg" alt="">
</div>
<div class="project">
<img src="project6.jpg" alt="">
</div>
<div class="project">
<img src="project7.jpg" alt="">
<img src="project8.jpg" alt="">
</div>
<div class="project">
<img src="project9.jpg" alt="">
</div>
2
Answers
You can chunk the collection to two and one items in it respectively: