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

abkrim's avatar
Level 13

How to language for Illuminate/AuthNotifications/ResetPassword.php

Hi.

It's possible or how to, convert class Illuminate/AuthNotifications/ResetPassword.php into localizable class?

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

if made any changes on this file (->line(trans('some.file.array.value')), when change lost.

0 likes
6 replies
Snapey's avatar

this is in a trait?

you can overload it in your own controller by duplicating the function with exactly the same name

abkrim's avatar
Level 13

Thanks.

I don't know well traits.

A new way for learn PHP.

Thanks.

Snapey's avatar

Sorry, my mistake. This is not in a trait, and surprisingly seems to be hard coded into the notifications file.

I will keep looking...

zachleigh's avatar
Level 47

In your User model:

use App\Notifications\ResetPassword;


    /**
     * Send the password reset notification.
     *
     * @param string $token
     */
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new ResetPassword($token, $this->username()));
    }

Then make your own ResetPassword notification class:

<?php

namespace App\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class ResetPassword extends Notification
{
    /**
     * The password reset token.
     *
     * @var string
     */
    public $token;

    /**
     * Username for user.
     *
     * @var string
     */
    public $username;

    /**
     * Create a notification instance.
     *
     * @param  string  $token
     * @return void
     */
    public function __construct($token, $username)
    {
        $this->token = $token;
        $this->username = $username;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return ['mail'];
    }

    /**
     * Build the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
            ->from('[email protected]', 'AppName')
            ->subject(trans('general.reset_password_subject'))
            ->greeting(trans('general.reset_password_greeting', ['username' => $this->username]))
            ->line(trans('general.reset_password_line1'))
            ->action(trans('general.reset_password'), url('password/reset', $this->token))
            ->line(trans('general.reset_password_line2'));
    }
}
2 likes
dimitri.koenig's avatar

With the newest Laravel v5.6.24 all those lines including the subject is localizable, as the ResetPassword Notification has changed:

    public function toMail($notifiable)
    {
        if (static::$toMailCallback) {
            return call_user_func(static::$toMailCallback, $notifiable, $this->token);
        }
        return (new MailMessage)
            ->subject(Lang::getFromJson('Reset Password Notification'))
            ->line(Lang::getFromJson('You are receiving this email because we received a password reset request for your account.'))
            ->action(Lang::getFromJson('Reset Password'), url(config('app.url').route('password.reset', $this->token, false)))
            ->line(Lang::getFromJson('If you did not request a password reset, no further action is required.'));
    }
2 likes

Please or to participate in this conversation.