Laravel twitter bootstrap:显示视图数据 [英] Laravel twitter bootstrap: showing data on views

查看:98
本文介绍了Laravel twitter bootstrap:显示视图数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在查询我的数据库


$ b

$ 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()以下布局来做到这一点,我尝试了很多方法,但都没有成功。

解决方案

$ entertainments 你得到的变量是一个集合,所以你可以对它使用方法 chunk()。它将Collection分割成更小的。请阅读此处



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


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.

解决方案

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

这篇关于Laravel twitter bootstrap:显示视图数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆