I have followed Jeffery Way in Laravel 8 from scratch amazing series but I’m having a trouble in pagination. In the index page we’re making our latest post to have a specific styling and then first 2 posts comes after with a different styling and then rest of posts in different styling. The problem is that these styles are carrying over with us to page2 and 3 and …etc
I want to make this to only posts in page1 or homepage and when I go to page 2 I should have a default styling for all posts.
This is the index
<x-bloglayout>
@include('posts.__header')
@if ($posts->count())
<x-featuredCard :post="$posts[0]" />
@if ($posts->count() > 1)
<div class="lg:grid lg:grid-cols-2">
<x-postCard :post="$posts[1]" />
<x-postCard :post="$posts[2]" />
</div>
<div class="lg:grid lg:grid-cols-3">
@foreach ($posts->skip(3) as $post)
<x-postCard :post="$post" />
@endforeach
</div>
@endif
{{ $posts->links() }}
@else
<p class="text-center">No posts matches your search, please check back later</p>
@endif
</x-bloglayout>
I tried to use if directive to say if route is home or ?/page1 do this if not do that but it doesn’t seem to work.
This is my pagination:
public function index()
{
return view('posts.index', [
'posts' => Post::latest()->filter(request(['search', 'category', 'author']))->paginate(6)->withQueryString(),
]);
}
Thanks