Issue with locales and creating model records from a custom page
I've built a CSV Importer using a custom page, and have gotten to the point where I can successfully upload the file and start creating new records with my model/repository. But I'm running into an issue when it's trying to create the
slug
and translation
data.
Specifically, the active
column is not being set, and the `HasSlug::getSlugParams()
method doesn't know what to do with that since it's detecting that I should have locale info.
I can't figure out how to send along locale information from my custom page, or if there's another way to send or bypass this from my code to create the new record? I hope that makes sense. I'm on Twill 2.11.011 Replies
Hi, this package is very useful for exporting data, but I found that it can be complicated to work.
But its not immposible.
That package offers https://docs.laravel-excel.com/3.1/imports/collection.html which gets you an collection of records which you want to import.
After that you can use your Dealer Repository to create a new record.
This snippet is from my own code.
Best way to replicate this to override in your repo method
prepareFieldsBeforeSave
and dump or dd your incoming fields from frontend form. I explained that here https://discord.com/channels/811936425858695198/1040634143005999126Importing to collections | Laravel Excel
Supercharged Excel exports and imports in Laravel
languages
and published
are default fields. Languages contains array of locales which have 1 or 0 and that is used for the active
field.
ahhh ok
What Im not familiar in this case are
slugs
, you will need to check that on your own.
translates
and all other fields will be resolved like thisi think if i pass the language information as you've shown there that should take care of the
slugs
but i'll try this out and seeOnly some additional relathionships like media, files, tags needs to be added via relation to this, but since you dont need that, Ill will not write about that.
I'm getting this error when attempting to import now, something to do with the languages being published? i tried to pass values for
published
with a language array but that didn't workJust a tip in general, you can use the browser inspector to see in what form the data is being sent. From there you can deduct what structure you need to pass to the create method.
thanks @Harings Rob and @kalle, my import is working now!
If you dont use description, you can remove it. That was just for an example.
ha good catch, i should be using it 🙂 thanks again!