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

[8.x] Allow request input to be retrieved as a collection #38832

Merged
merged 3 commits into from
Sep 17, 2021

Conversation

erikgall
Copy link
Contributor

Description

This PR adds the ability to retrieve input from an incoming request as a collection. In our codebase, I have noticed that we are commonly retrieving input from the request, defaulting it to an empty array and passing it to the collect helper. If a key is not given it will return all of the request's input as a collection. If a key is not found, it will default the input to [] and return an empty collection.

Before

collect($request->input('users', []))->each(function ($user) {
    // ...
});

After

If approved, it would allow for a straight forward shortcut to retrieve the requested input / input key as a collection:

$request->collect('users')->each(function ($user) {
    // ...
});

Thanks!

@taylorotwell taylorotwell merged commit 4cb7660 into laravel:8.x Sep 17, 2021
@GrahamCampbell GrahamCampbell changed the title Allow request input to be retrieved as a collection [8.x] Allow request input to be retrieved as a collection Sep 17, 2021
victorvilella pushed a commit to cdsistemas/framework that referenced this pull request Oct 12, 2021
* Allow request input to be retrieved as a collection

* Fix docblock spacing -- styleci

* Remove default input value when collecting key
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.

3 participants