Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sdsheeks's avatar

Laravel 5 - Password reset link subject

Here is how I added a subject to the password reset link in L5. Please review and let me know if this looks good.

<?php namespace Megleaio\Http\Controllers\Auth;

use Megleaio\Http\Controllers\Controller;

use Illuminate\Foundation\Auth\ResetsPasswords;

use Illuminate\Http\Request;

use Illuminate\Auth\Passwords\PasswordBroker;

class PasswordController extends Controller {

use ResetsPasswords;

public function postEmail(Request $request)
{
    $this->validate($request, ['email' => 'required']);

    $response = $this->passwords->sendResetLink($request->only('email'), function($message)
    {
        $message->subject('Password Reminder');
    });

    switch ($response)
    {
        case PasswordBroker::RESET_LINK_SENT:
            return redirect()->back()->with('status', trans($response));

        case PasswordBroker::INVALID_USER:
            return redirect()->back()->withErrors(['email' => trans($response)]);
    }
}

}

0 likes
10 replies
RachidLaasri's avatar

This is the right way to do it, i see no problem in your code.

1 like
supermagiccow's avatar

The ResetsPasswords trait by default already attempts to read the subject of the email, so you don't really need to overload the method if that's the only thing you want to change, you can just add it to the constructor of the PasswordController class:

Using the default controller:

<?php namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Foundation\Auth\ResetsPasswords;

class PasswordController extends Controller {

    use ResetsPasswords;
    
    public function __construct(Guard $auth, PasswordBroker $passwords)
    {
        $this->auth = $auth;
        $this->passwords = $passwords;
        $this->subject = 'Your Password Reset Link'; //  < --JUST ADD THIS LINE
        $this->middleware('guest');
    }

}

2 likes
developeritsme's avatar

Or even much better :)

    public function __construct(Guard $auth, PasswordBroker $passwords)
    {
        $this->auth = $auth;
        $this->passwords = $passwords;
            $this->subject = trans('passwords.subject'); //add this line
        $this->middleware('guest');
    }

And keep all your 'settings' in language file - passwords.php in this case :)

3 likes
InstanceOfMichael's avatar

I wish the password reset logic was scaffolded into the project with a generator instead of hidden inside the framework.

1 like
sonesay's avatar

Hi All

I would like to extend the functions of this class vendor/laravel/framework/src/Illuminate/Foundation/Auth/ResetsPasswords.php.

I need to add in extra logic in those methods but I don't want to overwrite this code file. How would I go about extending this ?

vbounyar's avatar

Well, for me for 5.3, I had to make a custom class that extends the Notification in order to tweak with the reset email link and the subject line. I had to override the "toMail" function below:


public function toMail($notifiable)
{
         return (new MailMessage)
               ->subject('Your Password Reset Link')
               ->line('You are receiving this email because we received a password reset request for your account.')
               ->action('Reset Password', url('password/reset', $this->token).'?email='.urlencode($this->email))
              ->line('If you did not request a password reset, no further action is required.');

 }

Please or to participate in this conversation.