F
Filament6mo ago
Yohan

Exporter Importer on JSON model fields

I need to be able to export and import data from my model. To do this, I use Filament's Import and Export functions. My problem is that my model has a field called variables_form which contains a JSON that can vary from one model to another. And I'd like to generate a different column in my CSV export for each of the json keys contained in this field. Example: {"59": "Move and store your furniture, without moving from your home", "60": "Need to store your furniture during construction? We'll collect and store it for you! Order redelivery from your cell phone with us.", "61": "Best box"} I'd like this JSON to generate 3 different columns in my CSV. I've seen that columns can be managed using the public static function getColumns(): array method, but I can't generate my columns dynamically here, as I don't have access to the Model (which is necessary in my case to know how the variables_form field is made up). So the question is quite simple, how to handle this case with the export feature ?
6 Replies
stursby
stursby2mo ago
@Yohan I'm trying to do the exact same thing... did you ever find a solution?
Yohan
YohanOP2mo ago
@stursby I had to make a custom Job to handle my need. using LeagueCsv\Writer to handle writing to a csv file. Quite simple in the end. I can share a gist with you if you like.
stursby
stursby2mo ago
yea, that would helpful! I think I'll have to go the same route, as I need to generate dynamic column names based on a JSON db column key/value pairs
Yohan
YohanOP2mo ago
Gist
gist:2d72f794f8aaf8575f1ad9f7fbb5a567
GitHub Gist: instantly share code, notes, and snippets.
stursby
stursby2mo ago
C'est en Français! 😉 Thank for the snippet! 🙌
Yohan
YohanOP2mo ago
ahah GPT4 comments 🙃 You're welcome
Want results from more Discord servers?
Add your server