F
Filament6mo 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
Dhruva6mo ago
I am also facing same issue.
Jens
Jens6mo ago
I have this problem as well, relationship columns with dot notation just gets ignored.
BlackShadow
BlackShadow6mo ago
Same!
krekas
krekas6mo 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 Paauw6mo ago
I'm experiencing the same issue
chantha_huy
chantha_huy6mo ago
I have issues with timeout if datas more then 10000 row.
krekas
krekas6mo ago
Not related with this issue. And raise one at github
Patrick1989
Patrick19896mo ago
got a few mins left at the office cloning your repo now, maybe i can locate the issue well at a quick glance
Patrick1989
Patrick19896mo ago
i think this line is the issue
No description
Patrick1989
Patrick19896mo ago
g2g now but i wanna know this too will look again tomorrow
Patrick1989
Patrick19896mo ago
the relation is loaded when that line is called
No description
Patrick1989
Patrick19896mo ago
goes wrong earlier, the mapping only contais the ID
No description
Patrick1989
Patrick19896mo ago
in concerns/canExportRecords.php
Patrick1989
Patrick19896mo ago
No description
Patrick1989
Patrick19896mo ago
this line is removing the relation, because the 'isEnabled' is a level deeper in the array
Patrick1989
Patrick19896mo ago
No description
Patrick1989
Patrick19896mo 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...
Patrick1989
Patrick19896mo 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 Harrin6mo 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
Patrick1989
Patrick19896mo ago
ye my fix is not good enough maarten is good
Maarten Paauw
Maarten Paauw6mo 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...
Patrick1989
Patrick19896mo ago
nice work! thanks
Want results from more Discord servers?
Add your server
More Posts
Hide custom page in navigation without blocking accessI need to remove a custom page from the navigation but can't use `canAccess()` because users still nGrouped SelectsIs it expected, to lose grouped options when searching a select. When searching the parent of each Action form not validating?I thought form fields in this situation were validated automatically, but I'm getting an error `SQLSBefore createNewEntry ask for a related entry firstI want to create a function which opens a modal before the CreateAction of a Model in order to selec[3.2.0] Filter components doesn't update / generate blur eventHello. We are using DatePicker in filter like this: ```php Filter::make('filter') ->form([ Dynamic select not saving dataI have a `Edit Action` for a table row. In the form I have a `Select` field which is dependant of otGetting table/action styles to work outside a panelHi! I have a table in a full-page livewire component outside of a panel. The basic functionality worHow do you implement create / edit actions correctly within custom widgets?Hey everyone! I have been going around in circles a little bit with this and I think I am likely baHow do I load a model function before viewing the record?I am viewing a record but I want to mutate the data with a function that is defined in my model. HowImplementing a replacement of existing admin panel with Filament (6+ year old active SaaS project)Hi Everyone, I'm going to be documenting my journey replacing an existing admin panel for my SaaS (h