Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change email view path for password reset on Laravel

Using Laravel 5, I need 2 different views for password reset email. The default path to the email view is emails.password. But upon some conditions, I want to send emails.password_alternative.

How can I do this? (with PasswordBroker from Laravel)

This is my current code:

public function __construct(Guard $auth, PasswordBroker $passwords)
{
    $this->auth = $auth;
    $this->passwords = $passwords;
}

public function sendReset(PasswordResetRequest $request)
{
    //HERE : If something, use another email view instead of the default one from the config file
    $response = $this->passwords->sendResetLink($request->only('email'), function($m)
    {
        $m->subject($this->getEmailSubject());
    });
}
like image 356
Kalzem Avatar asked Mar 26 '16 22:03

Kalzem


1 Answers

For anyone interested in Laravel 5.2 you can set a custom html and text email view for password reset by adding

config(['auth.passwords.users.email' => ['auth.emails.password.html', 'auth.emails.password.text']]);

to the PasswordController.php in the constructor before the middleware call.

This overrides the app/config/auth.php setup for the PasswordBroker.

Blade Template for the password reset email is then located at:

yourprojectname/resources/views/auth/emails/password/html.blade.php yourprojectname/resources/views/auth/emails/password/text.blade.php

Took me long enough.

Credits: http://ericlbarnes.com/2015/10/14/how-to-send-both-html-and-plain-text-password-reset-emails-in-laravel-5-1/ http://academe.co.uk/2014/01/laravel-multipart-registration-and-reminder-emails/

like image 158
metanerd Avatar answered Oct 12 '22 14:10

metanerd