Skip to content

Paginator::resolveCurrentPage returns unexpected default value #43178

@brausepulver

Description

@brausepulver
  • Laravel Version: 9.17.0
  • PHP Version: 8.1.2

Description:

Hi, this is a very minor issue. I was trying check whether a route is paginated using Illuminate\Pagination\Paginator::resolveCurrentPage(default: false). Even though no pagination is ongoing, this returns 1 rather than false. Maybe it would be possible to return null in the default currentPageResolver:

Paginator::currentPageResolver(function ($pageName = 'page') use ($app) {
$page = $app['request']->input($pageName);
if (filter_var($page, FILTER_VALIDATE_INT) !== false && (int) $page >= 1) {
return (int) $page;
}
return 1;
});

The default value passed to resolveCurrentPage could then be returned by checking for null:
public static function resolveCurrentPage($pageName = 'page', $default = 1)
{
if (isset(static::$currentPageResolver)) {
return (int) call_user_func(static::$currentPageResolver, $pageName);
}
return $default;
}

Steps To Reproduce:

  1. In a route, invoke Illuminate\Pagination\Paginator::resolveCurrentPage(default: false) when there is no pagination.
  2. 1 is returned, rather than false.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions