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

bajki's avatar
Level 1

Laravel 8 Pagination page=1

Hi, i would like to remove page=1 from query.

Is there any way to overide url() function in AbstractPaginator

/**
 * Get the URL for a given page number.
 *
 * @param  int  $page
 * @return string
 */
public function url($page)
{
    if ($page <= 0) {
        $page = 1;
    }

    // If we have any extra query string key / value pairs that need to be added
    // onto the URL, we will put them in query string form and then attach it
    // to the URL. This allows for extra information like sortings storage.
    $parameters = [$this->pageName => $page];

    if (count($this->query) > 0) {
        $parameters = array_merge($this->query, $parameters);
    }

    return $this->path()
                    .(Str::contains($this->path(), '?') ? '&' : '?')
                    .Arr::query($parameters)
                    .$this->buildFragment();
}

with if ($page <= 1) { return $this->path(); }

Thanks.

0 likes
1 reply

Please or to participate in this conversation.