This episode is for members only

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

Get started
Already a member? Sign in to continue
Playing
19. Updating the processed rows

Transcript

00:00
As well as inserting these records we also want to update the import job so we can keep track of it. Of course we're not displaying that at the moment but we want to get this sorted now so we actually see this updated in the database. Now the first thing I'm going to do is just delete all of the
00:14
imports we already have in here and I'm also going to go ahead and truncate the customers tables so we can perform another import on this. So what we want to do then is using the import model that we've created and passed through for this specific import is update the processed rows. Now there are loads of different ways to do this you could go ahead and say this import update and you could
00:37
work it out that way or you could just say import increment and you could increment a particular column and the column that we want to increment is of course the processed rows. So we want to increment the processed rows column with a particular value. What's this going to be? Well it's going to be the affected rows by this particular statement. So to do this we can go
00:58
ahead and grab the affected rows and we can just very easily pass this through to here that's as simple as it gets. Of course you can update anything else you want inside of this job you could send an email really whatever you want to do. Okay so let's just take a look at this in action of course we've cleared the data out we've got no imports in there at the moment so let's go
01:18
ahead and choose that customers file go and map these up very quickly and then go ahead and hit import. Now we actually didn't restart our queue so we're going to have to do this again so I'm going to go ahead and wait for this to finish and just cancel this off rerun it and let's kind of start from scratch. So really important we want to make sure we update this every single time
01:42
you'll see that through this import here the processed rows. Oh it did actually work okay so the processed rows did work let's just try that again and just give this a refresh just so we know that we're good so let's upload this file go ahead and choose customers again map this up and hit import great and let's head straight to the database give this a refresh wait for that
02:06
to start rolling in and you can see that every second the processed rows are getting updated until we end up at 100 processed rows which means of course all of them records were inserted. So we've done that next episode let's look at marking this as completed once all of them jobs within that batch have completed.
25 episodes2 hrs 20 mins

Overview

Let's build a powerful CSV importer with Livewire, completely from scratch. This can handle millions of rows, be reused for multiple models, and by using job batches, doesn't require the browser to be open.

This course is for you if:

  • You need a robust importer 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 job batching and queues in Laravel
Alex Garrett-Smith
Alex Garrett-Smith
Hey, I'm the founder of Codecourse!

Comments

No comments, yet. Be the first to leave a comment.