Add function to return multiple rows in map for withMapping #14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This update allows map() to return multiple rows per item when exporting to CSV.
If the first element returned from map() is an array, it will now be treated as a list of sub-rows, which are iterated and written individually.
This function is available in laravel-excel.
Example use case
A typical scenario is when exporting data from a parent model with related items — for example, Users with their Cars.
Each car should produce its own CSV row, but it’s more convenient to reuse the existing logic and filtering on the User model rather than switch to the Car model and duplicate logic and/or filtering.