当用户添加新注释时,我使用通知向管理员发送电子邮件。如果我不使用ShouldQueue,一切都可以。。当我使用队列时,我得到了一个错误
ErrorException:未定义的属性:App\Notifications\NewKidNote::$note
原因可能是什么?这是我的通知代码
<?php
namespace AppNotifications;
use IlluminateBusQueueable;
use IlluminateContractsQueueShouldQueue;
use IlluminateNotificationsMessagesMailMessage;
use IlluminateNotificationsNotification;
use AppModelsKidNote;
class NewKidNote extends Notification
{
use Queueable;
protected $note;
protected $kidname;
protected $userfullname;
protected $color;
protected $sentnote;
protected $kidid;
public function __construct($note)
{
$this->note = $note;
$this->kidname = $note->kid->name;
$this->userfullname = $note->user->fullname;
$this->color = $note->color;
$this->sentnote = $note->note;
$this->kidid = $note->kid_id;
}
public function via($notifiable)
{
return ['mail','database'];
}
public function toMail($notifiable)
{
return (new MailMessage)
->subject('New Note added')
->greeting('Hello ')
->line('New Note has been added for '. $this->kidname. ' by '.$this->userfullname)
->line('Note Color: '.$this->color)
->line('Note')
->line($this->sentnote)
->action('You can also see the note here', route('admin.children.show',$this->kidid));
}
public function toDatabase($notifiable)
{
return [
'icon' => 'notepad',
'color' => $this->color,
'message' => 'New note added for '. $this->kidname ,
'link' => route('admin.children.show',$this->kidid)
];
}
}
自我提醒。。确保清理缓存并重新启动队列:((,然后它就可以正常工作了!!此代码运行良好。感谢