Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
Laravel Blade Loop

I am using ceil() method to count how many <div class="item"> block it should create. Each .item can only have 4 img.

I am having problem figuring out how to allow 4 img only and then create next .item block via loop.

    @foreach(range(1, ceil($product->photos->count()/4)) as $section)
    <div class="item">
        <div class="row">
            @foreach($product->photos as $photo)
                <img src="{{$photo->photo_url}}" alt="" data-target="#carousel" data-slide-to="{{$loop->index}}" class="galleryItem">
            @endforeach
        </div>
    </div>
    @endforeach
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can use chunk method in foreach like

  @foreach($posts->chunk(2) as $tempPosts)
  <div class = "row">
   @foreach($tempPosts as $post)
   /* your  code*/
   @endforeach
  </div>
  @endforeach

over 4 years ago · Santiago Trujillo Report

0

Use chunk():

@foreach($product->photos->chunk(4) as $photos)
    <div class="item">
        <div class="row">
            @foreach($photos as $photo)
                <img src="{{$photo->photo_url}}" alt="" data-target="#carousel" class="galleryItem">
            @endforeach
        </div>
    </div>
@endforeach
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!