Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

162
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda