TippyCracker49
TippyCracker49

Reputation: 21

Laravel pagination change from ?page=1 to /page/1

I want to change default Laravel pagination behaviour.

I want to change the query string to a route parameter:

https://www.example.com/blog?page=2

to this:

https://www.example.com/blog/page/2

I found this package but it is abandoned spatie/laravel-paginateroute

Any ideas? Thanks

Upvotes: 0

Views: 869

Answers (1)

dparoli
dparoli

Reputation: 9161

You can try with this route declaration:

Route::get('/blog/page/{page}', 'BlogController@index')->name('blog.index');

In your BlogController:

public function index($page)
{
    //paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
    $blogs = Blog::paginate(15, ['*'], 'page', $page);

    return view('blog.index', compact('blogs));
}

Upvotes: 2

Related Questions