Well, a quick search brought this good past answer up.
https://laracasts.com/discuss/channels/laravel/how-to-make-perfect-url-using-paginate-in-laravel
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, In laravel 8 I try to make listing with pagination with url like
http://site.com/admin/categories/page/3
and looking at branch https://stackoverflow.com/questions/20974404/laravel-pagination-pretty-url I tried to remade it for laravel 8 , replacing method getCurrentPage with ->path() method :
$links = $categories->links();
$patterns = array();
$patterns[] = '/'.$categories->path().'\?page=/';
$replacements = array();
$replacements[] = '';
echo '<pre>$patterns::'.print_r($patterns,true).'</pre>';
echo '<pre>$replacements::'.print_r($replacements,true).'</pre>';
// echo '<pre>$links::'.print_r($links,true).'</pre>';
echo preg_replace($patterns, $replacements, $links);
I see output :
$patterns::Array
(
[0] => //admin/categories\?page=/
)
$replacements::Array
(
[0] =>
)
But I got error :
preg_replace(): Unknown modifier 'a' (View: .../admin/categories/index.blade.php)
I tried to wrap like :
$patterns[] = '/'.preg_quote( $categories->path() ).'\?page=/';
Or
$patterns[] = '/'.addslashes( $categories->path() ).'\?page=/';
but got the same error anyway.
Which way is valid?
Thanks!
Well, a quick search brought this good past answer up.
https://laracasts.com/discuss/channels/laravel/how-to-make-perfect-url-using-paginate-in-laravel
Please or to participate in this conversation.