1

I studied the Laraval.s notifications. I can not realize how to send bulk notifications to the specific users. I know their ids.

Should I use private channel or broadcast?

1 Answer 1

2

in laravel there are two way to send notificatons

$user=User::find(1) ;
$users=User::all() ;
$user->notify(new InvoicePaid($invoice))
// or
Notification::send($users,new InvoicePaid($invoice))

so both ways send only one notification but we can send it to single or multiple users. if you need to send multiple notifications to multiple users you should use loops:

$notifications=[new InvoicePaid($invoice) ]
foreach($notifications as $notification)
{
Notification::send($users,$notification)

}

also there is a better way to handle this.you can use event and it is better to use event to send notification or perform other task after a specific action. for example define a event as userRegisterd. then you can assign one or more listener to this event like sendNewUserNotification , congratulationsNotification. in each listener notify the users

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.