In case the cell is an array or an object, it is recommended to implement WithMapping, because we can set the formatting for each column:
public function map($row): array
{
return [
$row->id, // integer
$row->name // string
json_encode($row->my_array) // array, print as json: "["a","b","c"]"
implode(', ', $row->my_array) // array, print in a user-friendly way: a, b, c
];
}
As you suggested in the source code, it would be nice to have a default formatting approach for arrays. However, I am not quite sure which (json/implode) would be the best.
I would vote on "implode" approach - I guess it it more likely we want to print the values in a user-friendly way.
Hi @prageeth-peiris
Thanks for your suggestion.
In case the cell is an array or an object, it is recommended to implement WithMapping, because we can set the formatting for each column:
As you suggested in the source code, it would be nice to have a default formatting approach for arrays. However, I am not quite sure which (json/implode) would be the best.
I would vote on "implode" approach - I guess it it more likely we want to print the values in a user-friendly way.