sibarra's avatar

Laravel 5.3 pagination not retaining the current URL

Pagination not working properly, i am on below page

http://localhost.test/students/list

when i click on second page it is redirecting to the

http://localhost.test/?page=2

Not retaining actual url, it should redirect me to - http://localhost.test/students/list?page=2

any idea whats going wrong?

0 likes
2 replies
rin4ik's avatar

example of doing that

$posts = Post::with(['owner', 'category'])->paginate(5);
$posts->withPath('students');

The withPath method allows you to customize the URI used by the paginator when generating links. you should pass students to the withPath method.

Snapey's avatar

make sure you are paginating a GET route and that list is not a POST route

You should not need any special handling of the links

Please or to participate in this conversation.