Notify Multiple Users in Laravel

LaravelPosted on

Laravel supports a wide range of possibilities when we want to notify a user. Mostly, we want to notify only one user at the time, but also we have the back-end to notify multiple users at the same time.

With the help of the Notification facade, we can notify multiple users easily. Of course, you could just loop through a set of users, and call the $user->noitfy(…) method, but for sure it’s more elegant to avoid loops where it’s possible. So let’s see:

use Illuminate\Support\Facades\Notification;

// Get the users
$users = User::where(...)->get();

// Send the notifications
Notification::send($users, new TaskAssigned($task));
Note, if you are sending emails, don’t forget to queue them. Notifications support queues by default.

Need a web developer? Maybe we can help, get in touch!

Similar Posts

More content in Laravel category