简体   繁体   中英

Laravel notification email facade queue multiple users

Here is my code working to send notification email to multiple users

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

It works but if I want to delay it like that

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

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

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

Error is

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

How can I send notification email to multiple users using queue and Notification Facade ?

Thank's for help

试试这样:

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

I think you should try this:

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

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

OR

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

Hope this work for you!

With a foreach loop

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

It works, but if there is 1000+ users to notify, I'm not sure about the execution time :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM