我首先尝试加载页面,然后激活$ 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?
答案 0 :(得分:0)
在您的AppMailer sendInterestNotification *()方法中,将同步电子邮件递送替换为排队的电子邮件递送(请参阅Laravel文档中的Queueing Mail)
然后页面会立即返回,电子邮件将被放入相应的队列中。您必须编辑.env文件以更改QUEUE驱动程序并启动队列侦听器作为单独的进程,Laravel网站上提供了detailed documentation
您无法将页面返回浏览器,然后在控制器中运行一些额外的命令。