Skip to content

Commit

Permalink
fix: exporting of related models
Browse files Browse the repository at this point in the history
  • Loading branch information
yajra committed Sep 14, 2024
1 parent 3b9f5b2 commit d0c8fe5
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Services/DataTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Illuminate\Http\Response;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Illuminate\Support\LazyCollection;
use Maatwebsite\Excel\ExcelServiceProvider;
Expand Down Expand Up @@ -679,11 +680,18 @@ public function fastExcelCallback(): Closure
->reject(fn (Column $column) => $column->exportable === false)
->each(function (Column $column) use (&$mapped, $row) {
$callback = $column->exportRender ?? null;
$key = $column->data;

if (is_array($key)) {
$data = Arr::get($row, $key['_']);
} else {
$data = Arr::get($row, $key);
}

if (is_callable($callback)) {
$mapped[$column->title] = $callback($row, $row[$column->data]);
$mapped[$column->title] = $callback($row, $data);
} else {
$mapped[$column->title] = $row[$column->data];
$mapped[$column->title] = $data;
}
});

Expand Down

0 comments on commit d0c8fe5

Please sign in to comment.