0
votes

I am working on a module where you can create users and link them to specific restaurants. When a user is created, the manager of the restaurant and if set, the contact person of that restaurant gets a mail notification with the message that a new user is created and linked to that restaurant.

Now I'm trying to achieve the next case: when the notification is sent, al the added admin email addresses need to be notified with the same email, just like a bcc. But when I'm using the bcc and the notification is sent to like 2 users, the bcc will also send twice.

Since I can't add just email addresses to the Notification::send() method, I can't achieve this in one line of code. My current Notification:

Notification::send($users, new UserCreated($params));

How I think it should be done:

$emailAddresses = ['[email protected]', '[email protected]']
Notification::send([$users, $emailAddresses], new UserCreated($params);

How can I achieve this in the right way?

1
You're missing ) at the end of Notification::send( by the wayTarasovych
You can add one more user to $users variable, can't you?Tarasovych
@Tarasovych yes, but the admin emails are not always users objects, just an email addressDennis
The easiest way might be for you to create users with those email addresses. You could maybe add a role column and then give them an "admin" role so don't have to hard-code those email addresses.D Malan
@DelenaMalan Not sure why I didn't think about that, maybe that's the best solution indeed. It's Friday, my brain already has stopped working ^^Dennis

1 Answers

2
votes

From the docs:

On-Demand Notifications

Sometimes you may need to send a notification to someone who is not stored as a "user" of your application. Using the Notification::route method, you may specify ad-hoc notification routing information before sending the notification:

Notification::route('mail', '[email protected]')
            ->route('nexmo', '5555555555')
            ->notify(new InvoicePaid($invoice));

So, you can try something like this:

Notification::route('mail', '[email protected]')
            ->route('mail', '[email protected]')
            ->notify(new UserCreated($params));

route method