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

[5.6] Add sortKeys and sortKeysDesc methods to Collection. #23286

Merged
merged 1 commit into from
Feb 26, 2018

Conversation

pmatseykanets
Copy link
Contributor

This PR adds two convenience methods to Collection to allow sorting keys of the collection, or sorting the collection by the key if you wish.

  • sortKeys
  • sortKeysDesc

One of the use cases that I find myself a lot lately is grabbing an object via an API and rendering it's properties in a sorted fashion.

This PR allows to do something along the lines of

$this->renderLead(collect($this->getLeadViaAPI($id))->sortKeys());

instead of

$leadData = get_object_vars($this->getLeadViaAPI($id));
ksort($leadData);

$this->renderLead(collect($leadData));

or doing some unnatural combination of map and sort.

@tillkruss tillkruss changed the title Add sortKeys and sortKeysDesc methods to Collection. [5.6] Add sortKeys and sortKeysDesc methods to Collection. Feb 25, 2018
@taylorotwell taylorotwell merged commit 41da426 into laravel:5.6 Feb 26, 2018
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.

2 participants