[英]Laravel 7.x Illegal offset type
WelcomeMail.php;欢迎邮件.php;
public function __construct(User $user)
{
$this->user = $user;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('email.register-mail');
}
}
RegisterController.php;注册控制器.php;
protected function create(array $data)
{
$user =User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
$body = [];
$mailData = array('body'=>$body);
Mail::send('email.register-mail',$mailData, function ($message) use ($user){
$message->from(env('MAIL_USERNAME'), 'EksikParça.');
$message->subject('Hosgeldiniz!');
$message->to(new WelcomeMail($user));
});
return $user;
}
}
This is the code I wrote for the e-mail I send when the user registers.这是我为用户注册时发送的电子邮件编写的代码。 But I am getting an illegal offset type error.
但是我收到了非法偏移类型错误。 could be caused by why?
可能是什么原因造成的?
The to()
method in the Mail
expects the recipient. Mail
的to()
方法需要收件人。
You can either pass a user object to it or an email address.您可以将用户对象或电子邮件地址传递给它。
So try doing this instead:所以尝试这样做:
Mail::to($user)
->send(new WelcomeMail($user));
You can define the subject and from right in the Mail class.您可以在 Mail 类中定义主题和右侧。 Read more on that here: https://laravel.com/docs/8.x/mail#sending-mail
在此处阅读更多相关信息: https : //laravel.com/docs/8.x/mail#sending-mail
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.