Laravel 通知邮件门面队列多个用户
Laravel notification email facade queue multiple users
这是我的代码,用于向多个用户发送通知电子邮件
$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
如何使用队列和 Notification Facade 向多个用户发送通知电子邮件?
感谢您的帮助
我认为你应该试试这个:
$when = Carbon::now()->addSecond(10);
\Notification::send($users, new DealPublished($deal))->later($when);
或
\Notification::send($users, new DealPublished($deal))->when($when);
希望这对你有用!
使用 foreach 循环
$when = Carbon::now()->addSecond();
foreach($users as $user){
$user->notify((new DealPublished($deal))->delay($when));
}
有效,但如果有 1000+ 用户要通知,我不确定执行时间:D
这样试试:
\Notification::send($users, (new DealPublished($deal))->delay($when));
这是我的代码,用于向多个用户发送通知电子邮件
$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
如何使用队列和 Notification Facade 向多个用户发送通知电子邮件?
感谢您的帮助
我认为你应该试试这个:
$when = Carbon::now()->addSecond(10);
\Notification::send($users, new DealPublished($deal))->later($when);
或
\Notification::send($users, new DealPublished($deal))->when($when);
希望这对你有用!
使用 foreach 循环
$when = Carbon::now()->addSecond();
foreach($users as $user){
$user->notify((new DealPublished($deal))->delay($when));
}
有效,但如果有 1000+ 用户要通知,我不确定执行时间:D
这样试试:
\Notification::send($users, (new DealPublished($deal))->delay($when));