【问题标题】:Sending ResetPassword notification using queue in Laravel 6 - error property 'view'在 Laravel 6 中使用队列发送 ResetPassword 通知 - 错误属性“视图”
【发布时间】:2020-08-17 10:24:57
【问题描述】:

我想覆盖 laravel 6 中密码重置和电子邮件验证的默认通知,以尽可能以最简单的方式使用队列。所以我在 User.php 模型中添加方法:

use App\Notifications\ResetPasswordNotification;
use App\Notifications\EmailVerificationNotification;
...
public function sendPasswordResetNotification($token)
{
    $this->notify(new ResetPasswordNotification($token));
}

public function sendEmailVerificationNotification()
{
    $this->notify(new EmailVerificationNotification);
}

并创建新通知

重置密码通知

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Auth\Notifications\ResetPassword;

class ResetPasswordNotification extends ResetPassword implements ShouldQueue
{
    use Queueable;

}

EmailVerificationNotification

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;

use Illuminate\Auth\Notifications\VerifyEmail;

class EmailVerificationNotification extends VerifyEmail implements ShouldQueue
{
    use Queueable;

}

现在电子邮件验证正在排队发送,但在 url 中作为主机名正在生成 http://localhost/... 在默认通知中它是正确生成的,与浏览器中的域名相同(无需在 .env 文件中更改它)。

第二个问题是密码重置通知,根本没有发送。它给了我一个错误

Trying to get property 'view' of non-object at vendor/laravel/framework/src/Illuminate/Notifications/Channels/MailChannel.php:92

我不明白为什么会发生这种情况并且没有按预期工作。

搜索问题我什至发现了这个 (question),其中 fakemeta 提到它应该可以工作。

【问题讨论】:

    标签: notifications queue laravel-6


    【解决方案1】:

    我想通了。首先,在使用队列时,在我的情况下,我正在运行 artisan queue:work with supervisor daemon,作业在控制台下运行,因此没有可用的 SERVER['HTTP_HOST'] var,这意味着必须从 .env 读取此值文件。其次,当您像我一样更改代码覆盖方法时,您必须重新启动此队列:工作以重新读取更改。所以这些是我的主要问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-05
      • 2018-04-20
      • 1970-01-01
      • 2014-08-04
      • 2013-01-30
      相关资源
      最近更新 更多