我是laravel的新手,我想在用户登录应用程序之前验证每个用户的电子邮件。注册对我的数据库很好,但我遇到了这个错误:
类型错误:传递给Illuminate \ Mail \ Mailer :: send()的参数2必须是类型数组,给定字符串,在/ home / jayzdevera / Documents / CrudCCTV / cctv-crud / web / vendor / laravel中调用第221行/framework/src/Illuminate/Support/Facades/Facade.php
我想验证每个用户的电子邮件,所以这是我的代码:
public function store(CreateApplicantRequest $request)
{
$input = $request->all();
$confirmation_code = str_random(30);
$applicants = $this->applicantRepository->create([
'name' => $input['name'],
'email' => $input['email'],
'password' => bcrypt($input['password']),
'address' => $input['address'],
'cellphone_no' => $input['cellphone_no'],
'confirmation_code' => $confirmation_code
]);
Mail::send('email.verify', $confirmation_code, function ($message) {
$message->to(Input::get('email'), Input::get('name'))
->subject('Verify your email address');
});
Flash::message('Thanks for signing up! Please check your email.');
return redirect(url('applicant'));
}
public function confirm($confirmation_code)
{
if( ! $confirmation_code) {
throw new InvalidConfirmationCodeException;
}
$user = User::whereConfirmationCode($confirmation_code)->first();
if ( ! $user) {
throw new InvalidConfirmationCodeException;
}
$user->confirmed = 1;
$user->confirmation_code = null;
$user->save();
Flash::message('You have successfully verified your account.');
return Redirect::url('applicant');
}
答案 0 :(得分:1)
从错误中可以明显看出,您传递的是字符串而不是数组,将send
函数的第二个参数更改为数组
Mail::send('email.verify', compact('confirmation_code'), function($message) {
$message->to(Input::get('email'), Input::get('name'))
->subject('Verify your email address');
});
答案 1 :(得分:1)
你应该试试这个:
$confirmation_code = str_random(30);
$data = array('confirmation_code'=>$confirmation_code);
Mail::send('email.verify', $data, function($message) {
$message->to(Input::get('email'), Input::get('name'))
->subject('Verify your email address');
});
希望这对你有用!!!