dang
dang

Reputation: 2412

Laravel 5.0 URL change for pagination

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?

Upvotes: 2

Views: 1334

Answers (1)

Sergio Guillen Mantilla
Sergio Guillen Mantilla

Reputation: 1468

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;
});

Upvotes: 3

Related Questions