【发布时间】: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