Skip to content

Commit 89fce7c

Browse files
committed
Improve exporting of array & other data type values
1 parent a3ae56e commit 89fce7c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/Transformers/DataArrayTransformer.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,11 @@ protected function buildColumnByCollection(array $row, Collection $columns, stri
4545
$key = $column->data ?? $column->name;
4646
}
4747

48-
/** @var string $data */
4948
$data = Arr::get($row, $key) ?? '';
5049

5150
if ($type == 'exportable') {
5251
$title = $this->decodeContent($title);
53-
$dataType = gettype($data);
54-
$data = $this->decodeContent($data);
55-
settype($data, $dataType);
52+
$data = is_array($data) ? json_encode($data) : $this->decodeContent($data);
5653
}
5754

5855
$results[$title] = $data;
@@ -65,17 +62,21 @@ protected function buildColumnByCollection(array $row, Collection $columns, stri
6562
/**
6663
* Decode content to a readable text value.
6764
*
68-
* @param bool|string $data
69-
* @return string
65+
* @param mixed $data
66+
* @return mixed
7067
*/
71-
protected function decodeContent(bool|string $data): string
68+
protected function decodeContent(mixed $data): mixed
7269
{
7370
if (is_bool($data)) {
7471
return $data ? 'True' : 'False';
7572
}
7673

77-
$decoded = html_entity_decode(trim(strip_tags($data)), ENT_QUOTES, 'UTF-8');
74+
if (is_string($data)) {
75+
$decoded = html_entity_decode(trim(strip_tags($data)), ENT_QUOTES, 'UTF-8');
7876

79-
return str_replace("\xc2\xa0", ' ', $decoded);
77+
return (string) str_replace("\xc2\xa0", ' ', $decoded);
78+
}
79+
80+
return $data;
8081
}
8182
}

0 commit comments

Comments
 (0)