使用 Laravel routeNotifcationForMail() 发送到多个电子邮件地址?
Use Laravel routeNotifcationForMail() to send to multiple emails addresses?
我正在我的模型上使用 Notifiable
特征。
用户拥有以逗号分隔的订阅电子邮件列表(字符串)。
文档和我的背景阅读表明这只会路由到一个电子邮件地址。
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* Route notifications for the mail channel.
*
* @return string
*/
public function routeNotificationForMail()
{
return $this->email_address;
}
}
我也读过 Matt Stauffer on Notifications 但在那里看不到答案。
我的NotificationClass->toMail()
如下
/**
* Get the mail representation of the notification.
*
* @param Store $store
* @return mixed
* @throws Exception
*/
public function toMail(User $user)
{
return (new MailMessage)->view('notifications.emails.activity-roundup', compact('user'));
}
我猜你需要下面的代码,因为你可以发送数组 (see here):
/**
* Route notifications for the mail channel.
*
* @return string
*/
public function routeNotificationForMail()
{
return $this->emailsToArray();
}
private function emailsToArray() {
if (is_null($this->email_addresses)) {
return $this->email; //default email
}
//perform more checks that you need
return array_map('trim', explode(',', $this->email_addresses))
}
我正在我的模型上使用 Notifiable
特征。
用户拥有以逗号分隔的订阅电子邮件列表(字符串)。
文档和我的背景阅读表明这只会路由到一个电子邮件地址。
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use Notifiable;
/**
* Route notifications for the mail channel.
*
* @return string
*/
public function routeNotificationForMail()
{
return $this->email_address;
}
}
我也读过 Matt Stauffer on Notifications 但在那里看不到答案。
我的NotificationClass->toMail()
如下
/**
* Get the mail representation of the notification.
*
* @param Store $store
* @return mixed
* @throws Exception
*/
public function toMail(User $user)
{
return (new MailMessage)->view('notifications.emails.activity-roundup', compact('user'));
}
我猜你需要下面的代码,因为你可以发送数组 (see here):
/**
* Route notifications for the mail channel.
*
* @return string
*/
public function routeNotificationForMail()
{
return $this->emailsToArray();
}
private function emailsToArray() {
if (is_null($this->email_addresses)) {
return $this->email; //default email
}
//perform more checks that you need
return array_map('trim', explode(',', $this->email_addresses))
}