To alert the user by email once the export is completed, we're just going to go through exactly the same process here and we're going to create another job.
00:07
Let's call this notifyUserOfExport and let's go ahead and add this to the chain that we have here, notifyUserOfExport. What do we need to pass through here? Well we need to know the actual currently logged in user and the export itself. Let's head over to the notifyUserOfExport job and let's fill in the user here. It's the user that we're going to notify and of course the export itself which we can use to grab some details from. So initially what we're going to do is just redirect the user from the email over to the exports page.
00:45
We don't actually have that at the moment so why don't we go ahead and just build that out really quickly. So let's just keep this as a view. So I'm going to go ahead and duplicate this dashboard down. Let's call this exports and reference exports. We'll keep the same middleware and let's give this a name of exports. So let's go and make out a view here called exports. Let's grab the dashboard template and let's go to exports.blade.php, paste this in, get rid of the transactions table and we'll switch the title over to exports.
01:21
So we should now basically have an exports page that we can link through to in that email. A little bit later we'll update the email so we actually link through to download the specific export file. But for now we'll just link through to this page which will eventually show all of our exports. Okay let's build this email out then. So we've already gone ahead and over in our export modal attached this notifyUserOfExport.
01:49
We've got the user, we've got the export in here. What do we do under handle? Well we just send an email so we can either do this as a notification for a user specifically or we could set this up as a separate email. Considering we're always going to be notifying a particular user it makes more sense to create this as a notification. So let's go ahead and say phpArtisan make notification and we'll just call this export ready.
02:15
So under handle we now just take the user, we notify them and we pass in a new export ready notification which we've just created. And of course we pass through the export so this notification is aware of that and can generate a link to the download a little bit later. So let's again make sure that we are accepting in that export and let's just fill in the via which is just mail. We can keep that as it is and here we can say something like your export is ready.
02:47
We can just you can customize this to do whatever you want. So let's say your export is ready. Let's get rid of this and let's change the action button here to view exports. And we know that we want to go through to that route that we've just created which is exports. So that's really plain for now but of course feel free to add on to this, send a traditional mail whatever you want to do.
03:14
To test this out we'll bring up whichever local email client we're using and I'm just going to go and grab the port here and switch this over in my application. So let's go over to EMV under mail. I'm using hello to test this locally but you could either switch the mailer to log that will dump this to your Laravel log file. Or you can go ahead and use any other solution that you're using like mail pit pretty much anything.
03:39
Okay so we've got email set up and we can now just check that this email gets sent once the export is finished. So I'm just going to go ahead and clear everything out in the database again. I'm going to come over here and get rid of this file just so we can start fresh and let's see what happens. So we're going to go and just select a few transactions here.
03:59
Hit start export and okay great. So this is our first issue notify users of export. We just open that up probably just a namespace issue just in here. Yeah we just want to make sure we import that.
04:13
Let's try this one more time. So let's go over export this again just make sure that we get rid of that too. Export this out and there we go that's completed. And if we open up our mail client we should have an email sent through.
04:30
That didn't actually work so to debug this we can head over to Horizon and check failed jobs. And yeah that looked like it should have actually sent that out but it didn't. It might just be that we need to go ahead and restart Horizon. So let's do that and then we'll try the export process again.
04:49
Okay so over in our editor let's restart Horizon. And let's try this one more time. Okay so I'm going to select 10 of these export these out. And let's go back over to our mail client and there we go perfect.
05:04
So we just needed to restart Horizon. You can see here we've received an email with your export is ready. And we can click view exports which should take us over to our exports page. Which we're going to be building next.
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