andyandy
1 month ago

Remove ?page=1 from paginate()

Posted 1 month ago by andyandy

I had this problem:

blah.com/articles //my main article page
blah.com/articles?page=1 //is duplicate with previous page
blah.com/articles?page=2
blah.com/articles?page=3

So i published pagination template and used this preg_replace to remove ?page=1

//previous button link
<a class="page-link" href="{{preg_replace('/\?'.$paginator->getPageName().'=[1]$/','', $paginator->previousPageUrl())}}" rel="prev" aria-label="@lang('pagination.previous')">&lsaquo;</a>

//numbered page links
<li class="page-item"><a class="page-link" href="{{preg_replace('/\?'.$paginator->getPageName().'=[1]$/','',$url)}}">{{ $page }}</a></li>

It worked well, when I was using:

$records->links();

Problem is, it will stop working when I use:

$records->appends(request()->input())->links()

Please sign in or create an account to participate in this conversation.