php - Laravel Mailable - 试图获取非对象的属性“电子邮件”
问题描述
我有以下可邮寄的:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class UserLoginDetailsMail extends Mailable
{
use Queueable, SerializesModels;
protected String $username;
protected String $email;
protected String $password;
/**
* Create a new message instance.
*
* @param String $username
* @param String $email
* @param String $password
*/
public function __construct(String $username, String $email, String $password)
{
$this->username = $username;
$this->email = $email;
$this->password = $password;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this
->from('test@test.com', env('TENANT_NAME'))
->replyTo(env('TENANT_EMAIL'))
->to($this->email)
->subject('Test')
->view('api.emails.user-login-details')
->with([
'username' => $this->username,
'password' => $this->password,
]);
}
}
像这样被解雇:
Mail::queue(new UserLoginDetailsMail('test', "test@test.com", "test"));
但是,我排队的作业遇到以下错误:
ErrorException: Trying to get property 'email' of non-object in /vendor/laravel/framework/src/Illuminate/Mail/Mailable.php:612
/**
* Set the recipients of the message.
*
* All recipients are stored internally as [['name' => ?, 'address' => ?]]
*
* @param object|array|string $address
* @param string|null $name
* @param string $property
* @return $this
*/
protected function setAddress($address, $name = null, $property = 'to')
{
foreach ($this->addressesToArray($address, $name) as $recipient) {
$recipient = $this->normalizeRecipient($recipient);
$this->{$property}[] = [
'name' => $recipient->name ?? null,
'address' => $recipient->email,
];
}
return $this;
}
这个排队的邮件正在另一个排队的作业中被触发,不确定这是否会产生任何影响。
谢谢
解决方案
代码看起来不错。不过,您可能在没有重新启动队列的情况下对代码进行了更改。根据 Laravel 文档:
由于队列工作者是长期存在的进程,因此如果不重新启动,他们不会注意到代码的更改。因此,使用队列工作者部署应用程序的最简单方法是在部署过程中重新启动工作者。您可以通过发出 queue:restart 命令优雅地重新启动所有工作人员:
php artisan queue:restart
推荐阅读
- verilog - 用于 CMOS 3 输入 XNOR 门的晶体管级 Verilog 模块
- javascript - 如何适应 JS 框架和库?
- java - 如何检测仅由不推荐使用的方法或类递归使用的类?
- python-3.x - 编写递归案例
- django - 尽管嵌套到公司模型,但未显示表单
- python - Python 请求 + Marketo REST API
- ios - 当应用程序在前台时收到 Twilio 通知警报
- r - 在 tidyverse 中使用自定义函数
- javascript - 升序或降序排序在 Safari 桌面上不起作用
- reactjs - 在 Heroku Deploy 上找不到但在本地找到的模块