在我的store方法中,我使用$ request请求,但是当传递给显示未定义变量请求错误的Mail::send
方法时。
public function store(Request $request)
{
$user = new User();
$user->add_user($request);
$confirmation_code = ['123456'];
Mail::send('users.add-user', $confirmation_code, function($message) {
$message->to($request->get('email'), $request->get('email'))
->subject('Verify your email address');
});
return redirect('/users')->with('success', ['Thanks for signing up! Please check your email.']); ;
}
答案 0 :(得分:2)
在你的Mail :: send闭包中,你必须传递$request
变量,如下所示:
Mail::send('users.add-user', $confirmation_code, function($message) use ($request) {
$message->to($request->get('email'), $request->get('email'))
->subject('Verify your email address');
});
答案 1 :(得分:1)
请尝试此代码..
public function store(Request $request)
{
$user = new User();
$user->add_user($request);
$confirmation_code = ['123456'];
Mail::send('users.add-user', $confirmation_code, function($message) use($request) {
$message->to($request->email, $request->email)
->subject('Verify your email address');
});
return redirect('/users')->with('success', ['Thanks for signing up! Please check your email.']); ;
}
答案 2 :(得分:0)
您应该添加use()
以将变量传递到闭包范围:
Mail::send('users.add-user', $confirmation_code, function($message) use($request) {