Emile P.
Emile P.

Reputation: 3962

Sending sms to multiple phone numbers with Laravel Notifications

I'm developing a web site and would like to send a sms message to multiple phone numbers with Nexmo, using Laravel 5.4.

My application has a one-to-many relationship between a User (Notifiable) and PhoneNumber model. The latter has user_id and number fields.

I'd like to use the elegant Notifications system Laravel offers and just be able to send a message to ALL of a given user's phone numbers by doing $user->notify(new FooNotification()).

I have tried routing the notification by adding a routeNotificationForNexmo function to my User model and returning the phone numbers as an array of strings, but as expected that returns an error ('array to string conversion').

Any ideas? Thanks in advance.

Edit: for now, I've made PhoneNumber implement Notifiable as well, then I'll just have to invoke notify() for each of a user's phone numbers... I'm still hoping for a better solution though.

Upvotes: 1

Views: 2287

Answers (1)

Alexander Glöss
Alexander Glöss

Reputation: 56

  1. Add the Notifiable trait to your PhoneNumber model. (I see you've already done this)
  2. Add the routeNotificationForNexmo function to the PhoneNumber model.
  3. Use the Notification facade like so: Notification::send($user->numbers, new FooNotification)

Upvotes: 2

Related Questions