需要在laravel 5.2中的每一行之后给出行类

时间:2017-05-29 05:21:49

标签: laravel laravel-5.2 row

我想在每一行显示3个结果。 1结果包含图像,标题和描述。如果描述很长,第二行中的第4个结果将会中断。所以我需要在每一行之后给出。我尝试了以下代码,但没有工作。提前谢谢。

<div class="row">
    @if(count($reports['data']) > 0)
        @foreach($reports['data'] as $reportsUser)

            <div class="col-md-4 wow">
                <article class="post post-2 post-2_mod-c clearfix">
                    <div class="entry-media">

                        @if($reportsUser['image'])

                            <img src="{{ asset(App\Http\Controllers\Controller::getThumbPath($reportsUser['image'])) }}"
                                 alt="Foto" class="img-responsive" style="width:360px;height:192px;"/>
                        @else

                            <img src="{{asset('images/no_image.jpg')}}" alt="Foto" class="img-responsive"/>

                        @endif
                    </div>
                    <div class="entry-main">
                        <div class="entry-header">
                            <h2 class="entry-title ">{{$reportsUser['title']}}</h2>
                        </div>

                        <div class="entry-content">
                            <p>{!! str_limit($reportsUser['description'],127,"....") !!}</p>
                        </div>
                        <div class="entry-footer"><a href="{{ url('view-report/'.$reportsUser['id'])}}"
                                                     class="btn-link clsComClrRed">Continue Reading</a></div>
                    </div>
                </article>
            </div>

        @endforeach
    @endif
</div>

1 个答案:

答案 0 :(得分:1)

将您的@foreach声明更改为:

@foreach($reports['data'] as $i => $reportsUser)

然后,就在您的第一个@endforeach之前(以及</div>之后),添加:

@if ( $i % 3 == 2 )
    <div class="clearfix"></div>
@endif