I am using laravel pagination to paginate my products By default It gives me url like this
http://example.test/search?page=3
But I want some like
http://example.test/search/page/3
OR If Possible
http://example.test/search
On every page
This Is How I am doing it now but it is not giving me any result
{{ $books->appends(Request::except('page'))->links() }}
And I have also tried like this
$books = Book::paginate(10);
$books->withPath('/search');
But still no result
You can use this to generate custom link where you use link() in your blade.php.
@php
$links = $books->links();
$pattern = $replacement = array();
$pattern[] = '/'.$books->getCurrentPage().'\?page=/';
$replacement[] = '';
$customLinks = preg_replace($pattern, $replacement, $links);
echo $customLinks;
@endphp
Also you can use a package named laravel-paginateroute from spatie in github.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With