简体   繁体   English

将Laravel通知副本发送给管理员

[英]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. 但是,当我使用密件抄送并将通知发送给2个用户时,密件抄送也会发送两次。

Since I can't add just email addresses to the Notification::send() method, I can't achieve this in one line of code. 由于我不能仅将电子邮件地址添加到Notification::send()方法,因此我无法在一行代码中实现。 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方法,可以在发送通知之前指定临时通知路由信息:

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 路线方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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