Laravel twitter bootstrap:显示视图数据 [英] Laravel twitter bootstrap: showing data on views
问题描述
我正在查询我的数据库
$ 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()
以下布局来做到这一点,我尝试了很多方法,但都没有成功。
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屋!