Reputation: 75
I want my application will send a email after 10 minutes of sending another email.
In my application
Now I want to
Below is the function where for user setup .
public function finishUserSetup($Sub){
if($Sub == 0){
$subscription = SubscriptionPlans::where('identifier', '=', "Monthly")->first();
$expiry = date('Y-m-d', strtotime('+' . $subscription->months . ' months'));
$sub_period = "monthly";
} else{
$subscription = SubscriptionPlans::where('identifier', '=', "Annually")->first();
$expiry = date('Y-m-d', strtotime('+' . $subscription->months . ' months'));
$sub_period = "annually";
}
$this->expiry_date = $expiry;
$this->user_type = "SUB";
$this->subscription_period = $sub_period;
$this->update();
$replaceArray = array(
'fullname' => $this->forename . " " . $this->surname,
'subscriptionName' => $subscription->name,
);
EmailTemplate::findAndSendTemplate("paymentconfirm", $this->email, $this->forename . " " . $this->surname, $replaceArray);
}
In the above function the last line of code is the one which sends a payment confirmation email to the user which is
EmailTemplate::findAndSendTemplate("paymentconfirm", $this->email, $this->forename . " " . $this->surname, $replaceArray);
I want to execute the following line of code 10 minutes after the above one
EmailTemplate::findAndSendTemplate("WelcomeTips", $this->email, $this->forename . " " . $this->surname, $replaceArray);
How to run the above line of code after 10 minutes
Upvotes: 2
Views: 1290
Reputation: 116
First set up the queue configuration in your laravel project . then create a job with
php artisan make:job YourNameJob
Transfer the email sending process into YoutNameJob , and finally dispatch YoutNameJob twice in the finishUserSetup method, like this
public function finishUserSetup($Sub){
.
.
.
YoutNameJob::dispatch([arguments])->delay(now());
YoutNameJob::dispatch([arguments])->delay(now()->addMinutes(10));
}
Upvotes: 1