3

I am trying to override the actionUrl that is being put in an Email to reset a users account. But it stays the same no matter what I do. I tried overriding in my Route files. Can anybody help me ?

Here is the route in my routes file :

Route::get('cms/password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');

Here is my email template :

<p style="{{ $style['paragraph-sub'] }}">
    <a style="{{ $style['anchor'] }}" href="{{ $actionUrl }}" target="_blank">
        {{ $actionUrl }}
    </a>
</p>` 

I know actionUrl is defined in SimpleMessage.php but I don't know where it's set.

balping
  • 7,518
  • 3
  • 21
  • 35
TenTimesCake
  • 75
  • 2
  • 8

1 Answers1

6

The link is set in Illuminate\Auth\Notifications\ResetPassword. This is the notification being sent out on a password reset request.

This notification is initialized in Illuminate\Auth\Passwords\CanResetPassword which is a trait pulled in nowhere else, than your App\User model.

So all you need to do is to create your own reset notification and override the sendPasswordResetNotification method on your User model, as shown below:


php artisan make:notification MyResetPasswordNotification

Edit app/Notifications/MyResetPasswordNotification.php

<?php

namespace App\Notifications;

use Illuminate\Notifications\Messages\MailMessage;


class MyResetPasswordNotification extends \Illuminate\Auth\Notifications\ResetPassword
{
    /**
     * Build the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    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('YOUR URL', $this->token))
            ->line('If you did not request a password reset, no further action is required.');
    }
}

Then add this to app/User.php

/**
 * Send the password reset notification.
 *
 * @param  string  $token
 * @return void
 */
public function sendPasswordResetNotification($token)
{
    $this->notify(new \App\Notifications\MyResetPasswordNotification($token));
}

Of course, you'll need to create your own route, as you wrote in the question and you'll have to change blade views too.

balping
  • 7,518
  • 3
  • 21
  • 35