如何限制这个循环..只有三个循环..感谢您的帮助

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


?>


蓝山帝景
浏览 195回答 2
2回答

慕标琳琳

您可以使用loop变量 https://laravel.com/docs/5.5/blade#the-loop-variable@foreach($all_published_products as $product)&nbsp; &nbsp; @if($loop->index > 2)&nbsp; &nbsp; &nbsp; &nbsp; @breack&nbsp; &nbsp; @endif&nbsp; &nbsp; .........@endforeach

元芳怎么了

最好的方法是在模型中查询。
打开App,查看更多内容
随时随地看视频慕课网APP