(bootstrap and php) How to create a row every 3 bank records

0

People, I have a template that has the following:

    <div class="row">

        <!-- INICIO -->
        <div class="col-md-4">
            Aqui vem uma imagem e o nome de um imóvel
        </div>

    </div>
        <!-- FIM -->

I'm looking for some real estate from the database, using laravel, but it could be any other framework.

I need to make a foreach, so I go through all the buildings and every 3 buildings I skip a line (create a new row) and insert each property into a column.

How can I do this foreach?

I'm very sure.

Thank you.

    
asked by anonymous 27.12.2017 / 18:57

2 answers

1

You can do something like this:

<?php $count = 0; ?>
<?php foreach($seus_imoveis as $imovel): ?>
    <?php if($count == 0): ?>
        <div class="row">
    <?php endif; ?>

    <div class="col-md-4">
        Aqui vem uma imagem e o nome de um imóvel
    </div>

    <?php $count+=1; ?>

    <?php if($count == 0): ?>
        </div>
    <?php endif; ?>

    <?php if($count==3) $count = 0; ?>

<?php endforeach; ?>

This way the first time will open div row and at the end of the third will close it, so on.

    
27.12.2017 / 19:06
0

I ended up using the example of the following link:

link

Using PHP's array_chunk function that separates an array into multiple arrays.

Then iterates as follows:

@foreach($imoveis as $imoveisLinha)

        <div class="row">

            @foreach($imoveisLinha as $imovel)
                <!-- INICIO -->
                <div class="col-md-4">
                        <div class="imovel-exibicao thumbnail">
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="faixa">
                                        <img src="img/imovel/ex.jpg" alt="" />
                                        <span class="faixa-padrao">Aluguel</span>
                                    </div>

                                    <div class="espacamento-imovel">
                                        <div class="titulo-imovel-ex">
                                            <a href="">Village Garavelo I - Casa 2 Quartos</a>
                                        </div>

                                        <div class="desc-imovel-ex">
                                            Lorem ipsum dolor sit amet, consectetur adipisicing elit. Eum molestiae tempora ipsa laborum explicabo rerum, odit assumenda. Perferendis distinctio corporis quidem aperiam nobis, explicabo vero, sint animi perspiciatis, omnis ipsum!
                                        </div>

                                        <div class="preco-imovel-ex">
                                            R$ 100.000,00
                                        </div>

                                        <div class="localizacao-imovel-ex">
                                            Goiânia
                                        </div>

                                        <div class="mais-info">
                                            <a href="imovel" type="button" class="btn botao">Mais Informações</a>
                                        </div>

                                    </div>

                                    <div class="info-imovel-ex hidden-sm hidden-xs">
                                        <div class="row">
                                            <div class="icones-info">
                                                <div class="col-sm-3">
                                                    <div class="i-metros" data-toggle="tooltip" data-placement="top" title="Metros"> 123m²</div>
                                                </div>

                                                <div class="col-sm-3">
                                                    <div class="i-quartos" data-toggle="tooltip" data-placement="top" title="Quartos"> 3</div>
                                                </div>

                                                <div class="col-sm-3">
                                                    <div class="i-banheiros" data-toggle="tooltip" data-placement="top" title="Banheiros"> 3</div>
                                                </div>

                                                <div class="col-sm-3">
                                                    <div class="i-garagens" data-toggle="tooltip" data-placement="top" title="Garagens"> 1</div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
            @endforeach
        </div>
    @endforeach
    
27.12.2017 / 19:23