How to Add Query Parameters to Laravel Pagination
In this lesson, we will see how to add query parameters to Laravel pagination.
Our goal in this lesson is to preserve the parameters like ?search=tom&page=3 during navigation.
Use the appends method
To solve this problem, use the appends method to avoid losing filters or search terms when navigating between pages.
<div class="row my-3">
<div class="col-md-12">
{{ $products->appends(request()->query())->links() }}
</div>
</div>