samedi 31 octobre 2015

PHP 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



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1M3t5jD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire