Skip to content

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.

v1r0x added a commit to DH-Center-Tuebingen/Spacialist that referenced this pull request Sep 5, 2025
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