Level 104
You probably are re-evaluating the relationship in the view; can you should the relevant part of your template?
Here's my code. When I dd($post) it shows 3 item but in view it shows all the 6 items I don't know. Neither it shows any error. I want to display only 3 posts.
public function categories($slug)
{
$category = Category::where('slug',$slug)->first();
$posts = $category->posts()->paginate(3);
$categories = Category::all();
$title = $category->name;
$settings = Setting::first();
return view('category',compact('category','categories','title','settings','posts'));
}
Here's the view
<div class="row">
@php
$i = 0;
@endphp
@foreach($posts as $post)
<div class="case-item-wrap">
<div class="col-lg-4 col-md-4 col-sm-6 col-xs-12">
<div class="case-item" style="margin-top: 20px;">
<div class="case-item__thumb">
<img src="{{$post->featured}}" alt="our case">
</div>
<h6 class="case-item__title"><a href="{{route('post.single',['slug' => $post->slug])}}">{{$post->title}}</a></h6>
</div>
</div>
</div>
@php $i++; @endphp
@if($i % 3 == 0)
<div class="row"></div>
@endif
@endforeach
Please or to participate in this conversation.