Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[13.x] fix bug: enhance handling of empty values in grouping#55875

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
comes wants to merge2 commits intolaravel:master
base:master
Choose a base branch
Loading
fromcomes:master

Conversation

comes
Copy link
Contributor

Description

This PR fixes a bug withingroupBy in collections. I understand it can be considered as a breaking change in 12.x, so maybe worth to consider to fix this issue in 13.x

How to reproduce

Prepare an array with some values, for demoing reasons, it's easier to spot the bug withpreserveKeys: true enabled.

collect([10 => [],20 => ['user' =>2,'roles' => []],// missing30 => ['user' =>3,'roles' => [null]],40 => ['user' =>4,'roles' => ['Role_2']]])->groupBy('roles', preserveKeys:true)  ->dump();

The output after grouping missing key20, because of roles is an empty array, while key30 is an array with a single value ofnull.

Solution

InsidegroupBy function, treat any empty array returned as a grouping key tonull before processing. This ensures that items with an empty array are grouped under the “null” bucket rather than being skipped.

@taylorotwelltaylorotwell marked this pull request as draftMay 27, 2025 21:44
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@comes

[8]ページ先頭

©2009-2025 Movatter.jp