Skip to content

Commit d757930

Browse files
committed
fix: support for array notation
1 parent d947b5b commit d757930

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Jobs/DataTableExportJob.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ public function handle(): void
127127

128128
$row = $row instanceof Arrayable ? $row->toArray() : (array) $row;
129129

130-
if ($this->usesLazyMethod() && is_array($row)) {
131-
$row = Arr::dot($row);
132-
}
133-
134130
$defaultDateFormat = 'yyyy-mm-dd';
135131
if (config('datatables-export.default_date_format')
136132
&& is_string(config('datatables-export.default_date_format'))
@@ -147,7 +143,7 @@ public function handle(): void
147143
}
148144

149145
/** @var array|bool|int|string|null|DateTimeInterface $value */
150-
$value = $row[$property] ?? '';
146+
$value = $this->getValue($row, $property) ?? '';
151147

152148
if (isset($column->exportRender)) {
153149
$callback = $column->exportRender;
@@ -231,6 +227,23 @@ protected function getExportableColumns(DataTable $dataTable): Collection
231227
return $columns->filter(fn (Column $column) => $column->exportable);
232228
}
233229

230+
protected function getValue(array $row, string $property): mixed
231+
{
232+
[$currentProperty, $glue, $childProperty] = array_pad(preg_split('/\[(.*?)\]\.?/', $property, 2, PREG_SPLIT_DELIM_CAPTURE), 3, null);
233+
234+
if ($glue === '') {
235+
$glue = ', ';
236+
}
237+
238+
$value = Arr::get($row, $currentProperty);
239+
240+
if ($childProperty) {
241+
$value = Arr::map($value, fn ($v) => $this->getValue($v, $childProperty));
242+
}
243+
244+
return $glue ? Arr::join($value, $glue) : $value;
245+
}
246+
234247
protected function usesLazyMethod(): bool
235248
{
236249
return config('datatables-export.method', 'lazy') === 'lazy';

0 commit comments

Comments
 (0)