Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 695
user2916349 Avatar asked Jan 16 '17 23:01

user2916349


2 Answers

Try it like this:

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

like image 68
Stubbies Avatar answered Oct 27 '22 11:10

Stubbies


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!

like image 34
AddWeb Solution Pvt Ltd Avatar answered Oct 27 '22 10:10

AddWeb Solution Pvt Ltd