Skip to content

Commit 739de49

Browse files
authored
Merge pull request #189 from yajra/patch-relation
fix: exporting of related models
2 parents 3b9f5b2 + d0c8fe5 commit 739de49

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/Services/DataTable.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Illuminate\Http\JsonResponse;
1313
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
1414
use Illuminate\Http\Response;
15+
use Illuminate\Support\Arr;
1516
use Illuminate\Support\Collection;
1617
use Illuminate\Support\LazyCollection;
1718
use Maatwebsite\Excel\ExcelServiceProvider;
@@ -679,11 +680,18 @@ public function fastExcelCallback(): Closure
679680
->reject(fn (Column $column) => $column->exportable === false)
680681
->each(function (Column $column) use (&$mapped, $row) {
681682
$callback = $column->exportRender ?? null;
683+
$key = $column->data;
684+
685+
if (is_array($key)) {
686+
$data = Arr::get($row, $key['_']);
687+
} else {
688+
$data = Arr::get($row, $key);
689+
}
682690

683691
if (is_callable($callback)) {
684-
$mapped[$column->title] = $callback($row, $row[$column->data]);
692+
$mapped[$column->title] = $callback($row, $data);
685693
} else {
686-
$mapped[$column->title] = $row[$column->data];
694+
$mapped[$column->title] = $data;
687695
}
688696
});
689697

0 commit comments

Comments
 (0)