notifications - 在 Laravel 6 中使用队列发送 ResetPassword 通知 - 错误属性“视图”
问题描述
我想覆盖 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;
}
电子邮件验证通知
<?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
而且我不明白为什么会发生并且没有按预期工作。
搜索问题我什至发现了这个(问题),fakemeta 提到它应该可以工作。
解决方案
我想到了。首先,在使用队列时,在我的情况下,我正在运行 artisan queue:work with supervisor daemon,作业在控制台下运行,因此没有可用的 SERVER['HTTP_HOST'] var,这意味着必须从 .env 读取此值文件。其次,当您像我一样更改代码覆盖方法时,您必须重新启动此队列:工作以重新读取更改。所以这些是我的主要问题。
推荐阅读
- python - 障碍物检测的分离轴定理
- database - 存储图像的最佳方法
- swift - HealthKit 会不断更新模拟器上的样本数据,但不会更新 Apple Watch 上的实际数据
- python - 解析请求后调用中的 ssl 证书数据时无法解密错误
- java - Junit:org.junit.ComparisonFailure 问题,在 mvn clean install 时添加了额外的 $jacocoData +XXXX
- java - WebFluxConfigurer 在 Spring webflux 中因功能路由而损坏?
- node.js - UnhandledPromiseRejectionWarning:错误:表的权限被拒绝
- android - 任务 ':app:kaptDebugKotlin' 执行失败 - 使用 Hilt 时发生错误
- scala - 根据地图的内容更新数据框的行
- bootstrap-4 - 引导程序中“标签”和“输入”之间的间距