F
Filament11mo ago
Wannes

[3.2.0] Export to CSV relationships

Hi there! I'm trying out Filament 3.2, and it's amazing! However, when I try to use the dot notation to add a relationship in the export it just ignores it. Am I missing something?
public static function getColumns(): array
{
return [
ExportColumn::make('name')
->label('Naam'),
ExportColumn::make('type')
->label('Type'),
ExportColumn::make('email')
->label('E-mail'),
ExportColumn::make('phone')
->label('Telefoon'),
ExportColumn::make('vat_number')
->label('BTW nummer'),
ExportColumn::make('address.address')
->label('Adres'),
ExportColumn::make('address.zip_code')
->label('Postcode'),
ExportColumn::make('address.place')
->label('Woonplaats'),
ExportColumn::make('address.state_or_province')
->label('Provincie'),
ExportColumn::make('address.country.name')
->label('Land'),
ExportColumn::make('registration_number')
->label('Ondernemingsnummer'),
ExportColumn::make('notes')
->label('Notities'),
];
}
public static function getColumns(): array
{
return [
ExportColumn::make('name')
->label('Naam'),
ExportColumn::make('type')
->label('Type'),
ExportColumn::make('email')
->label('E-mail'),
ExportColumn::make('phone')
->label('Telefoon'),
ExportColumn::make('vat_number')
->label('BTW nummer'),
ExportColumn::make('address.address')
->label('Adres'),
ExportColumn::make('address.zip_code')
->label('Postcode'),
ExportColumn::make('address.place')
->label('Woonplaats'),
ExportColumn::make('address.state_or_province')
->label('Provincie'),
ExportColumn::make('address.country.name')
->label('Land'),
ExportColumn::make('registration_number')
->label('Ondernemingsnummer'),
ExportColumn::make('notes')
->label('Notities'),
];
}
22 Replies
Dhruva
Dhruva11mo ago
I am also facing same issue.
Jens
Jens11mo ago
I have this problem as well, relationship columns with dot notation just gets ignored.
BlackShadow
BlackShadow11mo ago
Same!
krekas
krekas11mo ago
GitHub
Exporter can't export relationships data · Issue #10835 · filamentp...
Package filament/filament Package Version v3.2.2 Laravel Version v10.10 Livewire Version No response PHP Version v3.3.5 Problem description Exporter can't export relationships data, It will exp...
Maarten Paauw
Maarten Paauw11mo ago
I'm experiencing the same issue
chantha_huy
chantha_huy11mo ago
I have issues with timeout if datas more then 10000 row.
krekas
krekas11mo ago
Not related with this issue. And raise one at github
Patrick
Patrick11mo ago
got a few mins left at the office cloning your repo now, maybe i can locate the issue well at a quick glance
Patrick
Patrick11mo ago
i think this line is the issue
No description
Patrick
Patrick11mo ago
g2g now but i wanna know this too will look again tomorrow
Patrick
Patrick11mo ago
the relation is loaded when that line is called
No description
Patrick
Patrick11mo ago
goes wrong earlier, the mapping only contais the ID
No description
Patrick
Patrick11mo ago
in concerns/canExportRecords.php
Patrick
Patrick11mo ago
No description
Patrick
Patrick11mo ago
this line is removing the relation, because the 'isEnabled' is a level deeper in the array
Patrick
Patrick11mo ago
No description
Patrick
Patrick11mo ago
https://github.com/filamentphp/filament/issues/10835 i have updated the issue with my findings @Dan Harrin
GitHub
Exporter can't export relationships data · Issue #10835 · filamentp...
Package filament/filament Package Version v3.2.2 Laravel Version v10.10 Livewire Version No response PHP Version v3.3.5 Problem description Exporter can't export relationships data, It will exp...
Patrick
Patrick11mo ago
Changed the mapping code and it works now for relations
$columnMap = collect($data['columnMap'])
->flatMap(function (array $column, string $columnName) {
// If it's a simple column
if (isset($column['isEnabled']) && $column['isEnabled']) {
return [$columnName => $column['label']];
}

// If it's a relation
return collect($column)->filter(function ($subColumn) {
return is_array($subColumn) && ($subColumn['isEnabled'] ?? false);
})->mapWithKeys(function ($subColumn, $subColumnName) use ($columnName) {
return ["{$columnName}.{$subColumnName}" => $subColumn['label']];
})->all();
})
->all();

$columnMap = collect($data['columnMap'])
->flatMap(function (array $column, string $columnName) {
// If it's a simple column
if (isset($column['isEnabled']) && $column['isEnabled']) {
return [$columnName => $column['label']];
}

// If it's a relation
return collect($column)->filter(function ($subColumn) {
return is_array($subColumn) && ($subColumn['isEnabled'] ?? false);
})->mapWithKeys(function ($subColumn, $subColumnName) use ($columnName) {
return ["{$columnName}.{$subColumnName}" => $subColumn['label']];
})->all();
})
->all();

i made a pull request, but that code of filament just goes over my head sometimes, too abstract for me too follow 😛 this code works if you have relation, but 1 level deeper and it breaks again i think ( order.customer.adresses.street for example)
Dan Harrin
Dan Harrin11mo ago
@Patrick1989 changing line 126 to be collect(Arr::dot($data['columnMap'])) should fix all issues, right? actually collect($data['columnMap'])->dot() is prob better
Patrick
Patrick11mo ago
ye my fix is not good enough maarten is good
Maarten Paauw
Maarten Paauw11mo ago
@Patrick1989 I didn't realize you were busy with this issue as well. My PR just got merged. It solves the issue: https://github.com/filamentphp/filament/pull/10899
GitHub
Fix exporting relationship values by maartenpaauw · Pull Request #1...
Description Visual changes (if any) are shown using screenshots/recordings of before and after. Code style composer cs command has been run. Testing Changes have been tested. Documenta...
Patrick
Patrick11mo ago
nice work! thanks
Want results from more Discord servers?
Add your server