samedi 31 octobre 2015

Laravel 5 User class properties not accessible for sending Email after account creation

I have a problem where I can't put in the variables into the Mail::send() function in laravel. Please see the following code:

$first_name = $request->input('first_name'),
$email = $request->input('email'),

//Create account

User::create([
    'first_name' => $first_name,
    'last_name' => $request->input('last_name'),
    'email' => $email,
    'password' => bcrypt($request->input('password')),
]);

//Send email to user

Mail::send('emails.test', ['fname' => $first_name], function($message)
{
    $message->to($email)
            ->subject('Welcome!');
});

return redirect()
    ->route('home')
    ->with('info', 'Your account has been created and an authentication link has been sent to the email address that you provided. Please go to your email inbox and click on the link in order to complete the registration.');

For some reason the code breaks when it gets to the send email because I receive the error and the data is sent to the database. Why is the variable no longer accessible afterwards?

Any help would be greatly appreciated. Thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire