Skip to content

Commit e50fcb7

Browse files
committed
update Readme
1 parent 9d189fe commit e50fcb7

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Diff for: README.md

+27
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,33 @@ The field defintions are pretty flexible. Better learn by examples by yourself
205205
]
206206
```
207207

208+
## One row for each relation
209+
210+
If you have a relation you want to put into one row and preserve it's parent as one row if it hasn't a relation, you can
211+
use the following:
212+
213+
```php
214+
public function handle()
215+
{
216+
// ...
217+
218+
// relation has to be loaded in items of course
219+
$items->each(function (Item $item) use ($export) {
220+
$export->addRowForEachRelation($item, ['relation', 'more.*.relations'], 'fieldAccessorAlias');
221+
});
222+
223+
// ...
224+
}
225+
226+
public function fields(): array
227+
{
228+
return [
229+
'fieldAccessorAlias.fieldName' => 'Output of relation fieldName if it is existing',
230+
'fieldAccessorAlias.fieldNameMoreRelations' => 'Output of more.*.relations fieldName if it is existing',
231+
];
232+
}
233+
```
234+
208235
## SYLK file format error
209236

210237
By default, an exception getting thrown if the first column in the header row is named `ID`.

0 commit comments

Comments
 (0)