我在我的模型上使用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'));
}
答案 0 :(得分:2)
我想你想要下面的代码,因为你可以发送数组(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))
}