簡體   English   中英

Laravel 排隊時通知不起作用

[英]Laravel Notification doesn't work when queued

當用戶添加新注釋時,我正在使用通知向管理員發送電子郵件。 如果我不使用 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)
        ];
    }
}

注意自我..確保清理緩存並重新啟動隊列:))然后它工作正常。! 這段代碼運行完美。 謝謝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM