The effective solution for this issue that I have found is to edit the pagination template.
First publish the pagination template from the vendors using the following command from the root of the project:
php artisan vendor:publish --tag=laravel-pagination
Now a file at resources/views/vendor/pagination/default.blade.php
should be found and it could be edited like the following using str_replace()
for the urls of each page and back navigation button:
<li><a href="{{str_replace('?page=1','',$paginator->previousPageUrl())}}" title="{{__('Previous')}}" rel="prev">{{$foxPrev}}</a></li>
and
<li><a href="{{str_replace('?page=1','',$url)}}">{{ $page }}</a></li>
Update:
A bug was found with ?page=10
so instead of using str_replace
we should using preg_replace
like the following:
<li><a href="{{preg_replace('/\?page=[1]$/','',$url)}}">{{ $page }}</a></li>
Update 2:
In case of using any customized name for the page number parameter other than page
, we could use the paginator getter for the $pageName property like the following in the pagination template:
<li><a href="{{preg_replace('/\?'.$paginator->getPageName().'=[1]$/','',$url)}}">{{ $page }}</a></li>
To know more about how to use more than one pagination on the same page or how to customize the page number parameter $pageName
from view, checkout this answer