这是在 Laravel 中一次发送多封邮件的好方法吗?

Is this a good way of sending multiple mails at once in Laravel?

我还在学习Laravel,需要一些建议... 长话短说,我有一个小脚本,应该在他们的合同需要续约前 15 天向客户发送邮件。现在,代码确实有效。而且我们的客户名单相对较少。不过,我很好奇。这是一个好方法吗?有效率吗?使用数据库查询会更好吗? 无论如何,这是代码...

    $hosting=hosting::where('id','>',0);
    $dateToday=date('Y-m-d');
    $inFifteenDays=date('Y-m-d', strtotime($dateToday. ' + 15 days'));
    $hosting=$hosting->whereDate('datum_obnove','<=',($inFifteenDays));
    $hosting=$hosting->whereDate('datum_obnove','>=',($inFifteenDays))->get();
    foreach ($hosting as $hosting) 
    {
        $dataForSending=array();
        $dataForSending= array(
            'klijent' =>$hosting['kontakt'] , 
            'domena' =>$hosting['naziv_domene'],
            'mail' =>$hosting['mail']  
        );
    Mail::to($dataForSending['mail'])->queue(new HostingMail($hosting));
    }

提前致谢<3

欢迎使用 Whosebug!

确实有a lot of factors into when it's worth optimizing code before you hit an issue, but it looks like you're already utilizing Laravel queues which is a great first step. You'll at least be able to monitor your queues (https://horizon.laravel.com/ if you choose to use it) to see if they are getting bogged down or if there are issues. The former suggestion will need you to install Redis.

如果有问题,您可以修改 rate limiting 以确保您的应用程序仍能正常处理性能。

这些建议现在仍然很重要。我建议从您拥有的开始,监控性能,并在必要时使用上述建议。祝你好运!