简体   繁体   中英

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 = ['email1@test.com', 'email2@test.com']
Notification::send([$users, $emailAddresses], new UserCreated($params);

How can I achieve this in the right way?

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', 'taylor@example.com')
            ->route('nexmo', '5555555555')
            ->notify(new InvoicePaid($invoice));

So, you can try something like this:

Notification::route('mail', 'email1@test.com')
            ->route('mail', 'email2@test.com')
            ->notify(new UserCreated($params));

route method

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM