Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/245.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-如何在运行另一行代码10分钟后运行一行代码_Php_Laravel - Fatal编程技术网

PHP-如何在运行另一行代码10分钟后运行一行代码

PHP-如何在运行另一行代码10分钟后运行一行代码,php,laravel,Php,Laravel,我希望我的申请将在发送另一封电子邮件10分钟后发送一封电子邮件 在我的申请中 用户通过支付完成注册 应用程序向用户发送支付确认电子邮件 现在我想 在付款确认邮件发送10分钟后再发送一封电子邮件,其中包含欢迎提示 下面是用于用户设置的函数 public function finishUserSetup($Sub){ if($Sub == 0){ $subscription = SubscriptionPlans::where('identifier', '=

我希望我的申请将在发送另一封电子邮件10分钟后发送一封电子邮件

在我的申请中

  • 用户通过支付完成注册
  • 应用程序向用户发送支付确认电子邮件
现在我想

  • 在付款确认邮件发送10分钟后再发送一封电子邮件,其中包含欢迎提示
下面是用于用户设置的函数

   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);

  }
在上述功能中,最后一行代码是向用户发送支付确认电子邮件的代码

EmailTemplate::findAndSendTemplate("paymentconfirm", $this->email, $this->forename . " " . $this->surname, $replaceArray);
我想在上面一行代码10分钟后执行下面一行代码

EmailTemplate::findAndSendTemplate("WelcomeTips", $this->email, $this->forename . " " . $this->surname, $replaceArray);

如何在10分钟后运行上述代码行首先在laravel项目中设置队列配置。然后使用创建一个作业

 php artisan make:job YourNameJob
将电子邮件发送过程转移到YoutNameJob,最后在finishUserSetup方法中发送YoutNameJob两次,如下所示

 public function finishUserSetup($Sub){

   .
   .
   .

    YoutNameJob::dispatch([arguments])->delay(now());

    YoutNameJob::dispatch([arguments])->delay(now()->addMinutes(10));

  }

您应该使用调度程序,它不是在特定时间或定期运行的东西。只有在用户完成注册并确认付款后,才能使用作业并设置延迟。延迟(现在()->addMinutes(10))@ABOFAZLASOLI-可以在该函数中使用延迟。是的,它可以。。