Skip to content

Conversation

@Ashot1995
Copy link
Contributor

This pull request introduces an optional parameter to the Arr::dot and related helper methods, allowing developers to skip empty arrays when generating flattened keys.

By default, Arr::dot includes all keys, even those that point to empty arrays. In many cases—especially when working with configuration exports, validation rules, or API payload flattening—developers may prefer to omit empty arrays entirely to reduce noise or avoid redundant keys.

Implementation details:

Added a $skipEmptyArrays boolean parameter to the Arr::dot method and associated helper functions.
When set to true, the method skips keys whose values are empty arrays ([]).
Default behavior remains unchanged to ensure full backward compatibility.
Added unit tests to cover both scenarios (with and without skipping).

Example:

Arr::dot(['user' => ['name' => 'John', 'roles' => []]]);
// ['user.name' => 'John', 'user.roles' => []]

Arr::dot(['user' => ['name' => 'John', 'roles' => []]], skipEmptyArrays: true);
// ['user.name' => 'John']

Why this is useful:
This small enhancement provides more control over data flattening, reducing the need for additional filtering steps and improving readability in use cases where empty arrays carry no meaningful data.

@Ashot1995 Ashot1995 changed the title Add optional empty-array skipping to Arr::dot helpers [12.x]Add optional empty-array skipping to Arr::dot helpers Nov 12, 2025
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

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