Gammer Gammer - 5 months ago 11
HTML Question

Laravel twitter bootstrap: showing data on views

I am showing data to views where i have the following layout, And i have to use that layout.

I am querying my

DB
like this :

$entertainments = App\TalentTag::all()->random(5);


I have different
div
sizes that's why the problem occurs.

<div class="row">
<div class="col-xl-3 col-xs-12 col-lg-3 col-md-3 col-sm-3 small-boxes-left">
@include("user/components/small-category-box")
@include("user/components/small-category-box")
</div>
<div class="col-xl-6 col-xs-12 col-lg-6 col-md-6 col-sm-6 large-box-mid">
@include("user/components/big-category-box")
</div>
<div class="col-xl-3 col-xs-12 col-lg-3 col-md-3 col-sm-3 small-boxes-right">
@include("user/components/small-category-box")
@include("user/components/small-category-box")
</div>
</div>


Now how can
foreach()
the following layout to do this, I tried many ways but none worked.

Answer

The $entertainments variable that you get is a Collection, so you can use the method chunk() on it. It splits the Collection into smaller ones. Read about it here.

@foreach ($products->chunk(3) as $chunk)
    <div class="row">
        @foreach ($chunk as $product)
            <div class="col-xs-4">{{ $product->name }}</div>
        @endforeach
    </div>
@endforeach
Comments