我需要一些关于这个刀片模板的帮助,它是针对非营利组织的主页,我已经将它们的所有类别都放在主页上,我可以深入关系,以获得所需的消息,但我有一个问题在我的循环或什么,让我解释一下,我有一个主要块,每列两列我想显示4类相关的新闻,但我的循环再现每栏都有相同的输出,我如何获得2栏和8条正确格式的新闻,我的意思是没有重复的输出条目,谢谢。在两个靴带柱中显示雄辩数据(同一行)Laravel
的HomeController
$categories = Category::with('latestNews') ->orderBy('name', 'asc') ->take(9) ->get();
刀片模板
<!-- block_inner -->
<div class="block_inner row">
<!-- small_list_post -->
<div class="small_list_post col-lg-6 col-md-6 col-sm-6 col-xs-6">
<ul>
@foreach($category->latestNews->take(8) as $news)
<li class="small_post clearfix">
@if($news->Image_Thumb_Url)
<div class="img_small_post">
<img src="{{$news->Image_Thumb_Url}}" alt="{{$news->title}}">
</div>
@endif
<div class="small_post_content">
<div class="title_small_post">
<a href="#"><h5>{{ str_limit($news->title, 60, ' ...') }}</h5></a>
</div>
<div class="post_date"><i class="fa fa-calendar"></i> <em><a href="#">{{$news->created_at->diffForHumans()}}</a></em></div>
</div>
</li>
</ul>
</div>
<!-- // small_list_post -->
<!-- small_list_post -->
<div class="small_list_post col-lg-6 col-md-6 col-sm-6 col-xs-6">
<ul>
<li class="small_post clearfix">
@if($news->Image_Thumb_Url)
<div class="img_small_post">
<img src="{{$news->Image_Thumb_Url}}" alt="{{$news->title}}">
</div>
@endif
<div class="small_post_content">
<div class="title_small_post">
<a href="#"><h5>{{ str_limit($news->title, 60, ' ...') }}</h5></a>
</div>
<div class="post_date"><i class="fa fa-calendar"></i><em><a href="#"> {{$news->created_at->diffForHumans()}}</a></em></div>
</div>
</li>
@endforeach
</ul>
</div>
<!-- // small_list_post -->
</div>
我没看过的代码,但你肯定在你的数据库没有两条新闻是相似吗? –
嗨@Charlie,是的,我是postive关于它输出相同的记录两次,但我认为这是更多的我如何建立我的模板insinde我的循环,我也失去了一些东西,我正在阅读chunk()方法我认为这就是我必须使用的显示按照要求。或者可能是一个条件,如果它是第四个项目然后把bootsrap列然后完成与其余数据的循环。 –