Import Action: Import data for the belongsTo relationship without having foreign_id in CSV itself?
I need to import a CSV for the resource that belongsTo to another resource eg: I have a company and I need to import the staff for that company. But reading the document for the import, the only way we can do that is by having the company_id in the CSV itself. Is there a way to pass the company_id by ourselves in the Importer?
Solution:Jump to solution
I have solved it using the options method that ImportAction provides (it was staring right at me in the docs π
) https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import#using-import-options
First I used the
mutateFormDataUsing
ofActions
and passed id there and fetched that using the getOptions
of the importer, which worked but I was still not satisfied and remembered that there are the options in the docs too and I was doing something extra. I just opened the doc tab I had already opened and there it was. Well it is always good to try many possibilities π...3 Replies
Solution
I have solved it using the options method that ImportAction provides (it was staring right at me in the docs π
) https://filamentphp.com/docs/3.x/actions/prebuilt-actions/import#using-import-options
First I used the
mutateFormDataUsing
ofActions
and passed id there and fetched that using the getOptions
of the importer, which worked but I was still not satisfied and remembered that there are the options in the docs too and I was doing something extra. I just opened the doc tab I had already opened and there it was. Well it is always good to try many possibilities π@vanhellsing101 can you show me an example of how you did this?
Sure, ImportAction
In the Importer you can now access the
client_id
using $this->options['client_id']
example in resolveRecord
method