Using Laravel's pagination. It is working but when it gets to the last page it shows both the previous and next button. Is there a way to hid the "next" button?
public function index() {
$posts = Post::orderBy('created_at', 'desc')->paginate(10);
return view('posts.index', compact('posts'));
}
@foreach ($posts as $post)
{{$post->title}}
@endforeach
{!! $posts->links() !!}
{{ $posts->onEachSide(2)->links() }}
Yes, you can hide the "next" button on the last page in Laravel pagination by customizing the pagination links. Laravel's default pagination views provide a way to conditionally display the next and previous buttons. You can create a custom pagination view and modify it to hide the "next" button on the last page.
Locate the section that renders the "Next" button and add a condition to check if it's the last page. 3. Use the Custom Pagination View {!! $posts->links('vendor.pagination.default') !!}