0

我想创建一个具有通知功能的模型,

首先,在我的控制器中:

$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);
}

在构建()中:

public function build()
    {

        $email= $this->view($this->view);
        return $email;
    }

但它不起作用,我不知道错误在哪里?

4

1 回答 1

0

通知发送需要一个 Notifiable 对象,而不是电子邮件列表本身,如果您将其更改为此,您应该更进一步。

Notification::send($u3, new SendMailNotification($template,$subject,$request->input('mailFromTitle'),$attachments));
于 2019-06-13T07:22:30.310 回答