When we are importing and exporting data we need to be mindful of how we're formatting certain columns. Now we're using the amount as the kind of outlier example here. So what we're going to do now is add in a cost to this. So within our application we can actually see this as a dollar amount but then when we export it
00:19
we want to see this as a standardized amount and then when we import it we need to take a value like three dollars fifty and then transform this into an integer. So the reason I've left this as an additional episode is so we can focus on the cost of this and how it will interact with what we're doing a little bit later.
00:41
So how do we transform this value? There are a ton of different ways that we can do this but I always reach for the Laravel money package. So let's go ahead and install this and get this cost.
00:53
So if we head over to our application and pull this package in. Once that's done we're going to go ahead and head over to the cost section here which will give us a bunch of costs that we can use. Now we know that we are using integers within our database
01:06
so if we take this what we can do is over in our transaction here we can add to our cost. Now I added this date cost a little bit later we don't necessarily need this but the amount can now become a money integer cost and this class will handle taking the value in the database like the cents amount
01:27
and it will basically convert it over to something like this when we dump it out. And then if we import with this value like ten dollars that will be converted back over to an integer for us so we'll keep an eye on that a little bit later. For now though let's go back over to our application give this a refresh and there we go.
01:44
So we now have a nice formatted amount. Let's keep this in mind for when we're going through the process of exporting and importing and we'll keep an eye on how these values look as we generate our csv and as we take a csv and pull that back into our database.
22 episodes•2 hrs 18 mins•3 months 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