【问题标题】:Laravels 'Should Queue" resets mail text to defaultLaravel 'Shouldqueue' 将邮件文本重置为默认值
【发布时间】:2019-05-12 07:27:12
【问题描述】:

我在 laravel 中合并通知和队列时遇到问题...

如果我不使用队列并这样写通知

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\MailMessage;

class InterestingOfferPosted extends Notification
{
    public $offer;
    public function __construct($offer)
    {
        $this->offer = $offer;
    }

    public function via($notifiable)
    {
        return ['mail'];
    }

    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->subject('New Offer')
                    ->line("You have new offer:  ".$this->offer->name }
    }

这很好用,最后我得到了正确的文本,但是如果我让这个类实现“Illuminate\Contracts\Queue\ShouldQueue”类并使用“Illuminate\Bus\Queueable”特征,用户将收到默认的 laravel“The通知介绍。”邮件。 队列在任何其他情况下都很好,所以我认为我是对的,但在这种特殊情况下,它会改变最终结果。 有什么想法吗?

【问题讨论】:

    标签: laravel notifications queue


    【解决方案1】:

    我认为你这里没有实现队列接口

    use Illuminate\Contracts\Queue\ShouldQueue;
    use Illuminate\Bus\Queueable;
    use Illuminate\Notifications\Notification;
    use Illuminate\Notifications\Messages\MailMessage;
    
    class InterestingOfferPosted extends Notification  implements ShouldQueue{      
     use Queueable;
    

    【讨论】:

    • 当我这样做时它会发送空白邮件,就像它没有触及 toMail() 方法一样
    猜你喜欢
    • 2012-04-23
    • 2021-11-08
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 2014-04-11
    • 2022-01-05
    相关资源
    最近更新 更多