Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

toby's avatar
Level 31

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

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!!

0 likes
2 replies
toby's avatar
Level 31

Because I'm very tired of repeating ...->$paginate()->setPageName('seite') on most of the Controller's index() methods, I created the following helper function:

if (! function_exists('paginate')) {
    function paginate(\Illuminate\Database\Eloquent\Builder $builder)
    {
        return $builder->paginate()->setPageName('seite');
    }
}

So now I can use it like this:

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

    // after:
    $companies = paginate(Company::orderBy('name'));

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

If anyone knows about a better solution, I'd be glad to see this :)

Please or to participate in this conversation.