Laravel通知电子邮件门面排队多个用户

时间:2017-01-16 23:20:52

标签: php laravel notifications queue facade

以下是我的代码,致力于向多个用户发送通知电子邮件

$users = User::whereIn('id', $userIds)->get();
\Notification::send($users, new DealPublished($deal));

它有效,但如果我想延迟它

$users = User::whereIn('id', $userIds)->get();

$when = Carbon::now()->addSecond();

\Notification::send($users, new DealPublished($deal))->when($when);

错误是

FatalThrowableError in DealController.php line 226:
Call to a member function when() on null

如何使用队列和通知外观向多个用户发送通知电子邮件?

感谢您的帮助

3 个答案:

答案 0 :(得分:8)

试试这样:

\Notification::send($users, (new DealPublished($deal))->delay($when));

答案 1 :(得分:0)

我想你应该试试这个:

$when = Carbon::now()->addSecond(10);

 \Notification::send($users, new DealPublished($deal))->later($when);

\Notification::send($users, new DealPublished($deal))->when($when);

希望这对你有用!

答案 2 :(得分:0)

使用foreach循环

$when = Carbon::now()->addSecond();
 foreach($users as $user){
     $user->notify((new DealPublished($deal))->delay($when));
 }

它有效,但如果有1000多个用户要通知,我不确定执行时间:D