【问题标题】:Laravel twitter bootstrap: showing data on viewsLaravel twitter bootstrap:显示视图数据
【发布时间】:2016-10-28 10:24:27
【问题描述】:

我正在向具有以下布局的视图显示数据,并且我必须使用该布局。

我正在像这样查询我的DB

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

我有不同的div 大小,这就是出现问题的原因。

<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>

现在foreach()下面的布局如何做到这一点,我尝试了很多方法,但都没有成功。

【问题讨论】:

    标签: php html twitter-bootstrap laravel


    【解决方案1】:

    你得到的$entertainments变量是一个Collection,所以你可以对它使用chunk()的方法。它将集合拆分为更小的集合。阅读它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
    

    【讨论】:

    • 以下方法仍然显示所有 5 条记录。不知道为什么?
    猜你喜欢
    • 2020-06-09
    • 1970-01-01
    • 2013-12-09
    • 2021-08-11
    • 2023-01-08
    • 2017-01-26
    • 2013-06-11
    • 2013-03-03
    • 1970-01-01
    相关资源
    最近更新 更多