File tree 1 file changed +26
-2
lines changed
packages/Webkul/DataGrid/src/Exports
1 file changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -37,13 +37,37 @@ public function headings(): array
37
37
}
38
38
39
39
/**
40
- * Mapping .
40
+ * Map each row for export .
41
41
*/
42
42
public function map (mixed $ record ): array
43
43
{
44
44
return collect ($ this ->datagrid ->getColumns ())
45
45
->filter (fn ($ column ) => $ column ->getExportable ())
46
- ->map (fn ($ column ) => $ record ->{$ column ->getIndex ()})
46
+ ->map (function ($ column ) use ($ record ) {
47
+ $ index = $ column ->getIndex ();
48
+ $ value = $ record ->{$ index };
49
+
50
+ if (in_array ($ index , ['emails ' , 'contact_numbers ' ]) && is_string ($ value )) {
51
+ return $ this ->extractValuesFromJson ($ value );
52
+ }
53
+
54
+ return $ value ;
55
+ })
47
56
->toArray ();
48
57
}
58
+
59
+ /**
60
+ * Extract 'value' fields from a JSON string.
61
+ */
62
+ protected function extractValuesFromJson (string $ json ): string
63
+ {
64
+ $ decoded = json_decode ($ json , true );
65
+
66
+ if (json_last_error () === JSON_ERROR_NONE
67
+ && is_array ($ decoded )) {
68
+ return collect ($ decoded )->pluck ('value ' )->implode (', ' );
69
+ }
70
+
71
+ return $ json ;
72
+ }
49
73
}
You can’t perform that action at this time.
0 commit comments