2015-09-25 58 views
0

Layout相同的帖子顯示時間

這裏的問題是,紅色標記的新聞是相同的。我想在這裏做的是確保新帖子不會重複。因爲現在你可以看到相同的帖子在另一個帖子發佈之前顯示兩次。

這是代碼:

@extends('app') 

@section('content') 


    <div class="row"> 

     <div class="col-xs-12 col-sm-9"> 

      @if(count($latest)) 
      <div class="col-md-12"> 
      <a href="/post/{{$latest->slug}}/{{$latest->id}}"> 
      <img class="img-responsive" src="{!! url($latest->image) !!}" alt="" style="padding: 0px; height: 400px; width: 720px"></a> 
      <h2 class="post" style="margin-top: 0; color: #666"> 

       @foreach($latest->category as $cat) 
       <a style="color: red; text-transform: uppercase; font-size: 13px" href="/categories/{{$cat->name}}">{{$cat->name}}</a> 
       @endforeach 

      <br><a href="/post/{{$latest->slug}}/{{$latest->id}}">{!! strip_tags(link_to_action('[email protected]', $latest->title, [$latest->slug, $latest->id])) !!}</a></h2> 
      <span style="color: #b8b8b8">Paskeblta {{$latest->created_at}}</span> 
      <hr> 
      </div> 
      @else 
      <p>Nėra naujienų</p> 
      @endif 

      <div class="row"> 
      @foreach($posts as $post) 
      <div class="col-xs-6 col-lg-6"> 
      <a href="/post/{{$post->slug}}/{{$post->id}}"> 
      <img class="img-responsive" style="width: 352px; height: 180px" src="{!! url($post->image) !!}" alt=""></a> 
       <h3 class="post" style="font-size: 1.4em; margin-top: 0; color: #666"><small style="color: red; text-transform: uppercase; font-size: 11px"> 

       @foreach($post->category as $cat) 
       {{$cat->name}} 
       @endforeach 

       </small><br><a href="/post/{{$post->slug}}/{{$post->id}}">{{strip_tags($post->title)}}</a></h3> 
       <span style="color: #b8b8b8">Paskelbta {{$post->created_at}}</span> 
       <br><br> 
      </div><!--/.col-xs-6.col-lg-4--> 

      @endforeach 
      </div><!--/row--> 
     </div><!--/.col-xs-12.col-sm-9--> 

     @include('comp.sidebar') 
     </div><!--/row--> 

     <hr> 
@stop 
+0

可能需要一些控制器代碼來確定傳遞給模板的內容。 – ToothlessRebel

回答

1

你可以在迴路中增加一個檢查:如果當前的職位是一樣的特色之一,忽略它。

@foreach($posts as $post) 
    @unless ($post == $latest) 
     // rest of html goes here 
    @endunless 
@endforeach 

如果對象不是實際上相同的對象,只需相應地更改檢查 - 例如, @unless ($post->id == $latest->id)或類似的。

相關問題