简体   繁体   中英

Limit Laravel 5 pagination links

I have pagination with links [1, 2, 3, 4, 5, 6, 7, 8 ... 99, 100] and how can I change limit to display [1, 2, 3, ... 98, 99, 100] ? I have custom paginator class, but I can't find this limit to override in my new class.

By checking the classes I found that you have to override the presenter used by the Paginator.

Its done by calling render($presenter) your presenter must extend BootstrapThreePresenter If you wish to use bootstrap links and you just have to override the constructor and pass number of links you want on each side $this->window = UrlWindow::make($numberOfLinksEachSide)

These are just instructions you'll have to look by yourself, I'm sorry for not being able to provide complete code, I'm on phone. Please let me know if this worked.

You can do this easily by changing some core fields (although not recommended to change core files).

Find- vendor/laravel/framework/src/Illuminate/Pagination and go to UrlWindow . On this page find some parameters like- $onEachSide, $window . Change and play with these.

This is my solution to the same problems... In LengthAwarePaginator updated function links:

public function links($view = null, $data = [], $onEachSide = 3)
{
    if(!$data){
        $data = [];
    }
    $this->onEachSide = $onEachSide;
    return $this->render($view, $data);
}

And in URLWindow function make:

public static function make(PaginatorContract $paginator)
{
    return (new static($paginator))->get($paginator->onEachSide);
}

This removes the parameter $onEachSide from function make - which is never passed in anywhere - and allows it to be passed to function links as a parameter.

To use this you need to call this links method like this:

{{ $collection->links('view-to-use'|null, $dataArray|null, 2)}}

Where 2 is the number on each side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM