How should I define the exportAction exporter class in order to export hasMany relation?
Use case:
- I have a Product model, product has many prices.
I would like to export these prices in csv/excel format. Ideally add these values in separate columns:
SKU | PRODUCT_NAME | ..... | Price 1 | Price 2 |
Could you help me on this topic?
3 Replies
There’s no good way to dynamically create columns in a csv since you have no way of knowing the number of columns needed. Also makes importing more difficult too. I would recommend exporting the relationship in one column as a json or array string.
Hello awcodes,
thanks, finally I imploded the prices into one field separated by a pipe, and import back this way.
The main problem here, that the getColumns function is static, and it's content can't be change based on options.
You just need to make a custom exporter. https://filamentphp.com/docs/3.x/actions/prebuilt-actions/export