首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >how to limit this loop ..just three loops..thanks for loop

how to limit this loop ..just three loops..thanks for loop
EN

Stack Overflow用户
提问于 2019-09-23 16:21:28
回答 2查看 81关注 0票数 0
代码语言:javascript
复制
<?php

    @foreach($all_published_products as $product)

            <div>
                <div class="product-image-wrapper">
                    <div class="single-products">
                        <div class="productinfo text-center">
                            <img style="height: 150px;" src="{{URL::to($product->product_image)}}" alt="" />
                            <h5>{{$product->product_price}}</h5>
                            <p>{{$product->product_name}}</p>
                            <div style="">
                            @include('items.btn_add_cart_slider')
                            </div>
                        </div>
                    </div>
                </div>
            </div>

    @endforeach

?>
EN

回答 2

Stack Overflow用户

发布于 2019-09-23 16:25:17

您可以使用loop变量https://laravel.com/docs/5.5/blade#the-loop-variable

代码语言:javascript
复制
@foreach($all_published_products as $product)
    @if($loop->index > 2)
        @breack
    @endif
    .........
@endforeach
票数 1
EN

Stack Overflow用户

发布于 2019-09-23 16:25:18

最好的方法是在模型中查询。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58058330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档