laravel - 排队时 Laravel 通知不起作用
问题描述
当用户添加新注释时,我正在使用通知向管理员发送电子邮件。如果我不使用 ShouldQueue,一切正常。当我使用队列时出现错误
ErrorException:未定义的属性:App\Notifications\NewKidNote::$note
可能是什么原因?这是我的通知代码
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use App\Models\KidNote;
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)
];
}
}
解决方案
自我注意..确保清理缓存并重新启动队列:))然后它工作正常!!这段代码运行完美。谢谢
推荐阅读
- wordpress - wordpress:不同的页面有不同的菜单布局和位置
- git - Egit 中的远程跟踪分支后面有几个提交
- firebase - 通过 firebase 功能添加自定义用户属性
- php - 如何防止连接字符串开头的多余逗号
- javascript - 使用地图和加入javascript的优化方式?
- spring-boot - 获取相关 ID 为 158 的元数据时出错:{LEADER_NOT_AVAILABLE}
- ios - iOS - 没有重定向的 AppAuth
- javascript - 如何仅调试特定的产品元素?
- php - 为什么 Webklex\IMAP\Client::getFolders() 在 Exchange Server 上失败?
- ios - ipad:ipad 上更大的警报区域