Alfiza malek Alfiza malek - 9 days ago 6
PHP Question

$request variable is undefined

In my store method I am using the $request for Request but when passing to the

Mail::send
method showing an error that undefined variable request.

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.']); ;
}

Answer

In your Mail::send closure, you must pass the $request variable, like this:

Mail::send('users.add-user', $confirmation_code, function($message) use ($request) {
    $message->to($request->get('email'), $request->get('email'))
        ->subject('Verify your email address');
});
Comments