Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

161
Vistas
How to show an item after every three elements using PHP

I am trying to show an item after every three {{ $image->title }},
but my method used creates a bit delay in loading the page, i.e. when I remove <div class='extra'>, there is reduction of 200ms.
Is there any best alternate method for below?

@foreach( $images as $index =>$image)  
 <div>
   {{ $image->title }}
 </div>
  @if( count($images) > 0 && $index != 0 && ($index % 3) == 0 )
    <div class="extra">
      Item to show after three Image Titles
    </div>
  @endif    
@endforeach
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Laravel has its own Blade $loop variable that is meant to help you with this check out the docs here https://laravel.com/docs/8.x/blade#loops

In your case something like this makes more sense

 @foreach( $images as $index =>$image)  
 <div>
   {{ $image->title }}
 </div>
  @if( $loop->iteration % 3) // this can be $loop->index but im not sure what you need
    <div class="extra">
      Item to show after three Image Titles
    </div>
  @endif    
@endforeach
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda