Dennis
Dennis

Reputation: 1291

Send copy of Laravel notification to admin

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?

Upvotes: 0

Views: 2279

Answers (1)

Tarasovych
Tarasovych

Reputation: 2398

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

Upvotes: 2

Related Questions