2017-01-16 3 views
1

내 코드는Laravel 알림 이메일 외관 큐 여러 사용자가 여기에

$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 

대기열 및 알림을 사용하여 여러 사용자에게 알림 이메일을 보내려면 어떻게해야합니까? 케드? 도움

+0

''when'을'delay'로 바꾸고 다시 시도하십시오. – EddyTheDove

+0

DealController.php의 FatalThrowableError 라인 226 : null에 대한 멤버 함수 delay() 호출 – user2916349

+0

알림을 대기열에 넣으려면 https://laravel.com/에서 언급 한 것처럼 'ShouldQueue' 인터페이스와'Queuable '특성을 추가하십시오. docs/5.3/notifications # queuing-notifications. 그러나 그것은 당신이 특정 시간 (1 초)에 대한 알림을 예약/지연하려는 것 같습니다. doc을 참조하면,'delay'는'notify'에만 적용됩니다. 불행하게도, 배열로 호출 할 수는 없지만 사용자 당 호출 할 수는 있습니다. 어쩌면 for 루프일까요? 그냥 제안 해. – EddyTheDove

답변

2

은 다음과 같이 그것을 시도 :

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

0

에 대한

감사의 난 당신이 시도해야한다고 생각 :

$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 사용자가 있다면, 내가 실행 시간에 대한 확실하지 않다으로

+0

안녕하세요, 같은 오류가 발생했습니다. – user2916349