【发布时间】:2018-05-15 20:19:40
【问题描述】:
我正在为一个项目和一个有趣的困境寻求建议。
我的货运模型中有多个字段,它们是:
- shipto_id
- shipfrom_id
- billto_id
它们都(通过不同的关系)链接到我的客户模型:
public function billtoAccount()
{
return $this->belongsTo('App\Customer', 'bill_to');
}
public function shiptoAccount()
{
return $this->belongsTo('App\Customer', 'ship_to');
}
public function shipfromAccount()
{
return $this->belongsTo('App\Customer', 'ship_from');
}
而这些客户(实际上可能更适合描述为客户帐户(这些不是用户帐户,它们更像是与开展业务的每家公司的个人资料))可以拥有大量与之相关联的用户他们。
public function users()
{
return $this->belongsToMany(User::class);
}
现在,虽然我知道如何发送邮件和通知,但我很想知道如何将这些发送到多个用户的电子邮件。所以让我来描述以下内容:创建了一些东西,并引用了以下客户(反过来,他们的用户)。
- (billto_id) - 客户帐户 1 - 用户 1 (email1@example.com)
- (shipto_id) - 客户帐户 2 - 用户 2 (email2@example.com) 和用户 3 (email3@example.com)
- (shipfrom_id) - 客户帐户 37 - 用户 6 (email4@example.com)
现在,我将如何将用户的电子邮件转移到一组电子邮件中以向他们发送通知或邮件?
所以它应该会弹出:email1@example.com、email2@example.com、email3@example.com、email4@examples.com
【问题讨论】:
-
你不能循环遍历这三个关系并从相关模型中获取电子邮件吗?可能想要摆脱这样的心态,即这应该是一种雄辩的关系,而不仅仅是一种执行这种逻辑的方法。
标签: laravel email laravel-5 notifications