我正在尝试先加载页面,然后激活$mailer发送电子邮件。 因为当我点击转到下一页时,它需要时间,因为它发送电子邮件然后加载所以,
最好的方法是什么。或者任何方式。因为我想不通。
这是片段
public function sInterest($project_id, AppMailer $mailer)
{
$project = Project::findOrFail($project_id);
if($project->investment){
$mailer->sendInterestNotificationI($user, $project);
$mailer->sendInterestNotificationD($project, $user);
$mailer->sendInterestNotificationA($project, $user);
return view('projects.offer', compact('project'));
}
}
有没有办法$mailer返回页面后激活?
在 AppMailer sendInterestNotification*() 方法中,将同步电子邮件传递替换为排队电子邮件传递(请参阅 Laravel 文档中的排队邮件)
然后页面将立即返回,电子邮件将被放入相应的队列中。您必须编辑.env文件以更改QUEUE驱动程序并启动队列侦听器作为单独的过程,Laravel网站上提供了详细的文档
您无法将页面返回到浏览器,然后在控制器中运行一些额外的命令。