toby
234
2
Laravel

[L5.4] Pagination: Change query name for "?page=x" globally

Posted 1 year ago by toby

Hi everyone,

I want to rename the ?page=42 parameter name globally. Currently, what I've done is to use something like this:

// AppServiceProvider.php

public function boot()
{
    Paginator::currentPageResolver(function() {
        return $this->app['request']->input('seite');
    });
}

// XxxController.php

public function index()
{
    $companies = Company::paginate()->setPageName('seite');

    return view('companies.index', compact('companies'));
}

This works as expected!

Is there a way to set this globally (e.g. define the name in a service provider?)

Thanks in advance!!

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.