Ad

Laravel 5.0 URL Change For Pagination

- 1 answer

I want to change pagination URL for Laravel 5.0 from:

http://example.com/en/xyz?page=1

to

http://example.com/en/xyz/1

I have tried MULTIPLE solutions but nothing works for Laravel 5.0 here:

Laravel Pagination with pretty urls than query string

https://github.com/mayoz/pagination

Is there any fix available?

Ad

Answer

required page variable on your route definition and set a default value

Route::get('en/xyz/{page?}', function($page=1) {
    $limit = 10;
    $results = SomeModel::orderBy('someField')
        ->skip($limit * $page - 1)
        ->take($limit)
        ->get();
    return $results;
});
Ad
source: stackoverflow.com
Ad