John Davidson

php - Pagination next page refreshes same data

0 comments
Message:


I'm trying to do pagination and it's working fine. but i'm having little problem.


$selectedCategory = Course::where('course_category_id', $category->id)
->StatusOn()
->orderBy('created_at', 'desc')
->paginate(9);

when i added orderBy and when i'm clicking on next page it's getting same courses that was in first page and it's orderBy fault. But i need orderBy so what can i do?



My Answer:
>id)->paginate(10);

In order to refresh the data on the next page of pagination, you can use the following code:

php
$selectedCategory = Course::where('course_category_id', $category->id)->paginate(10)->appends(request()->query());


This code will append the query parameters from the current page to the next page, ensuring that the data is refreshed when navigating to the next page of pagination.

Rate this post

5 of 5 based on 1068 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us