Skip to content
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

[6.x] Allow developer to preserve query parameters on paginated Api resources #30745

Merged
merged 6 commits into from
Dec 5, 2019

Conversation

deleugpn
Copy link
Contributor

@deleugpn deleugpn commented Dec 3, 2019

Reattempt at #30729 without static configuration.

Instead of statically configuring it once, the developer would have to call ->preserveQueryParameters() after instantiating the Resource Collection, but I still like the DX with this case.

class MyHandler
{
    public function __invoke(MyRepository $repository)
    {
        return MyResourceCollection::make($repository->paginate())->preserveQueryParameters();
    }
}

@taylorotwell
Copy link
Member

Yeah this feels a lot better. Thanks.

@driesvints
Copy link
Member

Maybe rename the method to something less verbose? Thinking withUrl or something in the likes.

*
* @var bool
*/
protected $queryParameters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe shouldPreserveQueryParamters would be better and expressive.

@taylorotwell taylorotwell merged commit 43cf1db into laravel:6.x Dec 5, 2019
@taylorotwell
Copy link
Member

I tweaked this into two methods and did some renaming:

image

@deleugpn deleugpn deleted the append-query-parameters branch December 5, 2019 14:30
d8vjork added a commit to skore/laravel-json-api that referenced this pull request Jan 14, 2020
@BrandonSurowiec
Copy link
Contributor

Documentation will need to be added to laravel/docs for the new preserveQuery() and withQuery() methods.

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.

6 participants