Skip to content

[12.x] feat: Add current_page_url to Paginator #55789

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 20, 2025

Conversation

mariomka
Copy link
Contributor

Sometimes, it is useful to have the current page URL for the Paginator, for example, to customize how the pagination information is returned in the API resources collections:

class ApiResourceCollection extends AnonymousResourceCollection
{
    public function paginationInformation(Request $request, array $paginated, array $default): array
    {
        return [
            'links' => [
                'self' => $paginated['current_page_url'],
                'next' => $paginated['next_page_url'] ?? null,
            ],
        ];
    }
}

It simply adds a property to the toArray() method, so it shouldn't break anything.

@crynobone crynobone changed the title # [12.x] feat: Add current_page_url to Paginator [12.x] feat: Add current_page_url to Paginator May 20, 2025
@taylorotwell taylorotwell merged commit ec76574 into laravel:12.x May 20, 2025
61 checks passed
@cosmastech
Copy link
Contributor

I imagine that this is going to break a lot of unit tests for people who are asserting against the JSON structure without calling ->etc() [which I think is a best practice of writing tests against JSON responses, FWIW].

@fragkp
Copy link
Contributor

fragkp commented May 20, 2025

True! @taylorotwell Please revisit this change, this might be a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants