Because imports work pretty much in the same way as exports,
00:04
we're gonna do exactly the same thing when we start the import process, and we're gonna create out an import record in the database, which means we can monitor the import when we queue it.
00:14
So a little bit boring, but we're gonna go through the same process here of making out a model, which is now gonna be an import alongside a migration.
00:21
So let's do this as quickly as we can, because it's pretty much a replication of our exports. So each of our imports is gonna have a foreign ID, and that's gonna hook up to the user
00:32
that is actually going ahead and importing. Then again, we want to have, this isn't necessary, but we want some sort of record count in here, so we can sort of identify which one is which.
00:45
And we're gonna have a date time string in here for when this is completed at, which of course is again going to be nullable. What you could also do is store the file name
00:56
alongside of this, so then your users know which imports in the list are what, but we'll leave that for now. It's very easy to just pass that directly in.
01:05
So let's go ahead and run our migrations here. Let's go over to our user model. Of course, we need to create another relationship here for imports, so let's just swap that over to imports,
01:17
and we'll change this for import, and we're good to go. So now what we can do over here is start the process of our import. Once again, we're gonna do exactly the same thing
01:28
that we did when we created out the export, where we're taking the model that we're working with, so we can make this work for any of the data tables that we use.
01:39
Then we go ahead and create the import record, so just pretty much exactly the same thing, but this time referencing our imports, and we'll go ahead and create that out
01:48
with the record count, which we know we've already worked out because we are displaying it in that model. So we're just gonna say this record count,
01:57
and we should be good. Okay, so now let's just go ahead and die dump on that import just to make sure everything looks good, and let's try and import a file here.
02:07
So let's choose any of these, click start import, and yeah, okay, so a little bit of work to do here. Let's go over to our export actually, because we've got the casts here in Guarded,
02:17
which we can pretty much just copy over. So let's go ahead and pull these both in, and we should be good. Okay, and let's try the import on this one again,
02:27
and there we go, perfect. So over to the database, there we go, great. So record count is 10, completed that is now. Okay, I think we're pretty much done here.
02:35
We've created this record out. Now it's time to go ahead and create an importer, and actually pass this to our queue, and go ahead and get this import processing.
22 episodes•2 hrs 18 mins•1 month ago
Overview
Let's build a powerful CSV importer and exporter with Livewire, completely from scratch.
This can handle millions of rows, be reused for multiple models, and by using queues, doesn't require the browser to be open.
This course is for you if:
You need a robust drop-in importer and exporter component for your models that you have full control over
You want to brush up on some advanced Livewire concepts