'How to send mails from a jobs table using scheduler in laravel

I have many tables and for each, I want to use the Jobs table to send emails. And I also want to use a scheduler there.

But right now I am not able to send emails, I didn't get a solution from anywhere. Please I hope some of you will help me.

$schedule->call(function () {
            $select = DB::table('jobs')->select('payload','id')->get();
            foreach ($select as $val) {
                $command = json_decode($val->payload);
                $decode = unserialize($command->data->command);
                $data = ['spname' => $decode->mailable->data['spname'], 'name' => $decode->mailable->data['name'], 'useremail' => $decode->mailable->data['useremail'], 'password' => $decode->mailable->data['password']];
                Mail::to($decode->mailable->data['useremail'])->send(new WelcomeMail($data));
                DB::table('jobs')->where('id',$val->id)->delete();
            }
        })->everyMinute();

I have written this code but I think it is not the right way. Please help me with this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source