I am developing a Laravel blogging app.
I am trying to fetch articles in the database using a query builder but it doesn't seem to work for me.
What I want is to skip the top 3 latest articles and display only the 2 next articles (4th and 5th)
Here is my function:
public function getIndex() {
$posts = Post::orderBy('created_at', 'desc')->skip(3)->take(2)->get();
return view('pages.home')->with(['posts' => $posts]);
}
My blade view is structured like this:
<div class="col-lg-4 top-post-right">
@foreach ($posts as $post)
<div class="single-top-post">
<div class="feature-image-thumb relative">
<div class="overlay overlay-bg"></div>
<img class="img-fluid" src="/storage/{{$post->image}}" alt="">
</div>
<div class="top-post-details">
<ul class="tags">
<li><a href="#">{{ $post->category->name }}</a></li>
</ul>
<a href="{{ url('article/'.$post->slug) }}">
<h4>{{ $post->title }}</h4>
</a>
<ul class="meta">
<li><a href="#"><span class="lnr lnr-user"></span>Mark wiens</a></li>
<li><a href="#"><span class="lnr lnr-calendar-full"></span>{{date('j M, Y',strtotime($post->created_at))}}</a></li>
<li><a href="#"><span class="lnr lnr-bubble"></span>{{ $post->comments()->count() }} Comments</a></li>
</ul>
</div>
</div>
@endforeach
</div>
This is printing all the articles, does anyone know where I messed up?
</div>