This episode is for members only

Sign up to access "Build a Livewire CSV Importer/Exporter" right now.

Get started
Already a member? Sign in to continue
Playing
19. Marking an import as complete

Transcript

00:00
Once again the process of importing is pretty much a duplicate of exporting so what we can do is once we queue this we can continue to chain on with our own jobs. So now we are going to mark
00:12
the import as complete once it goes through the process of reading each of these sheets, rows and importing them into our database. So we will go ahead and make out a job here, make a job and let's call this mark import complete now instead. So let's new this up, mark import complete and we want to pass through the import into here. Now of course what you can
00:37
also do as part of this you can also send an email when complete. So if you want to go ahead and add in a notification like we did for exports you can go ahead and add that in as well as well as absolutely any other jobs in here that you want. Let's go ahead and get this mark import complete. So this is an import model and let's change that over to import and we are going to
01:05
just touch the completed at date, super simple. So this import touch completed at and we should be good that's pretty much all we need to do. Let's try it out. So I'm going to go to the database and just get rid of all of these imports and I'm going to go and just start a new import here with these 10 records. So let's go ahead and click start import. We'll handle the closing of
01:30
this modal and redirecting over to imports as well but you can see sure enough that's complete and we know that this already works. So let's finish up by just going over to our import modal and handling what happens here and really it's just a redirect to the imports route although of course you can do absolutely anything there that you want. Okay so I'm going to try this out
01:54
with a slightly larger data set with the import just so we can see it hang around. Let's not do this with too many records otherwise we're going to end up with waiting for hours. Let's go ahead and truncate out our transactions. So let's truncate these transactions we've got nothing in here. Let's get rid of this import and let's get rid of these exports as well here. So we're going
02:15
to use our factory just to seed a bunch of data here. So let's say tinker and let's go ahead and say how many do we want to do. We know that this is 1,000 per batch so let's do 5,000 and let's bump this up to 10 actually so 10,000 transactions will generate. I'm going to go ahead and export these so let's export every single one of these. Obviously that is now pending. I'm just going to
02:44
wait for a few minutes for this to finish and then we'll go ahead and re-import it back into our database and while we're doing that we could also get rid of these two files in here as well. Okay let's just wait for this to finish and oh it's already done so let's go over I might have already deleted that no there it is. So let's re-import this now into our database after we
03:05
again truncate this out. So we're just making sure that this is handling slightly larger ones so let's go ahead and import this file which should import 10,000 records for us. You see how quick that was as well to read that CSV despite it being slightly larger it was very very quick to grab the count of records. That is already complete and there we go they're already in the database.
22 episodes2 hrs 18 mins

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
  • You want to learn about queues in Laravel
Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Episode discussion

No comments, yet. Be the first!