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
23. Scoping imports

Transcript

00:00
Now we have these imports showing, we're going to go ahead and scope them not only by the model that we're currently working with but also the ones that have not completed because once they've completed we don't necessarily want to show them. So this is our current query that we're building up, we're just accessing the
00:16
imports relationship and we're ordering these by the oldest first. So time to head over to the import model and set up a couple of scopes. So let's first of all create one called not completed. So to go ahead and create the scope we're just going to prefix this with scope and into this
00:34
we're going to go ahead and receive in a builder and we'll just call that query and then from here we're going to go ahead and say query where null and completed at which is why we created that completed at column. So we can just really easily come over here now and just say not completed and we should be good. So let's just head over and give this a refresh,
01:02
this one hasn't completed but we can test this out by just filling that in in the database, coming back over and we shouldn't see it, great. Okay so let's go ahead and get rid of that completed at date just so we can test this scoping out again. Now we want something slightly different, we want to be able to scope this by the current model. So let's create out a
01:24
scope in here called for model, now into this we're going to get a builder but we also need to accept in the model that we want to scope this by. So really it's as simple as just saying query where model and then accessing that argument that we pass through. So let's go over to here and the only issue at the moment is within this particular component we're not passing
01:53
the model itself in. So if we head over to our csv importer here, let's go ahead and pass this model in, just reference it like this and then head over to the csv imports property just here, a component just here, and go ahead and create that model string out just there, great. Now we can go ahead and say for model and reference this model, great. So if we just head over now and give
02:22
this a refresh that is showing of course but if we just manually change this over to something else that we might have in the database, for example a product, then we won't expect to see that because we are not currently on the products page and we've not specified that as the model. Okay great, so let's go ahead and just change this back over to customer and we should be good.
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.