我要创建一个具有可通知功能的模型
首先,在我的控制器中:
$collection = collect([
[
'name' => 'user1',
'email' => 'user1@gmail.com',
],
[
'name' => 'user2',
'email' => 'user2@gmail.com',
],
[
'name' => 'user1000',
'email' => 'user1000@gmail.com',
],
]);
$u3 = new User3($collection);
当我返回$ u3-> getEmailList();时,输出为:
[{"name":"user1","email":"user1@gmail.com"},{"name":"user2","email":"user2@gmail.com"},{"name":"user1000","email":"user1000@gmail.com"}]
我的User3类是:
namespace App;
use App\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Notification;
use Illuminate\Notifications\RoutesNotifications;
use Notifications\EmailClientOfAccount;
class User3 extends User
{
use Notifiable;
public $emailList;
public function __construct($emails)
{
$this->emailList = $emails;
}
public function getEmailList()
{
return $this->emailList;
}
public function routeNotificationForMail($notification)
{
return $this->emailList['email'];
}
}
然后,我将$ u3传递给Notification:
Notification::send($u3->getEmailList(), new
SendMailNotification($ template,$ subject,$ request-> input('mailFromTitle'),$ attachments));
它显示以下错误:
Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function routeNotificationFor() on array
可以帮我解决这个问题吗?
预先感谢
// ------------------- 我纠正为:
Notification :: send($ u3,new SendMailNotification($ template,$ subject,$ request-> input('mailFromTitle'),$ attachments));
在“我的通知”中:
public function toMail($notifiable)
{
return new EmailTo($notifiable,$this->view,$this->topic,$this-
>mailFrom,$this->attaches);
}
以及在Build()中:
public function build()
{
$email= $this->view($this->view);
return $email;
}
但这不起作用,我不知道哪里出了错?
答案 0 :(得分:0)
通知发送需要一个可通知对象,而不是电子邮件列表本身,如果将其更改为该对象,则应该更进一步。
Notification::send($u3, new SendMailNotification($template,$subject,$request->input('mailFromTitle'),$attachments));