LumosMaxima's avatar

How to send mail once Job has been processed in the queue

Hi,

I have a situation where I need to upload huge data from csv file to database. I've managed to write a Job for processing the upload in the background using Queue. But I need to send a mail ( or even better, display a notification ) once the process has been completed. Please find below my Job for processing the upload ,

public function handle()
    {
        // Receive uploadedSheets from dispatcher
        // and process the uploads
        foreach($this->uploadedSheets as $sheetData)
        {   
            // 
             $tz = new Timezone();
             if(!empty($sheetData->timezone))
             {
                 $tz->name = $sheetData->timezone;
             }
             $tz->status = true;
             $tz->save();
         }
        Mail::to("[email protected]")->send(new TimezoneImported);
    }

The Mail method I've used here didn't work and I'm noob to Events too. Please explain if possible how to fire an event to display notification in the front-end or send a mail to user once upload is completed. Thank you.

0 likes
3 replies
ctroms's avatar

Have a look at the Job Events

You can use the after method to send the email once your upload is complete.

1 like
LumosMaxima's avatar

Any sample code for this? I'm a little inexperienced in this.

ctroms's avatar

There is sample code in the documentation link I sent. If you are having difficulty with any specific part of it, post your code and I'm sure a number of people here, myself included, would be happy to help.

Please or to participate in this conversation.