Skip to content

Commit

Permalink
[8.x] Add the password reset URL to the toMailCallback (#38552)
Browse files Browse the repository at this point in the history
* Add the password reset URL to the toMailCallback

It is useful to receive the generated reset URL in the callback, because if we want to only change the mail template texts (ResetPassword::toMailUsing(function($user, $token) {}) we have to generate it ourselves.

Backwards compatibility is kept, as it is a new parameter.

* Update ResetPassword.php

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
NilLlisterri and taylorotwell authored Aug 26, 2021
1 parent 21d2fb2 commit 9eb835f
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/Illuminate/Auth/Notifications/ResetPassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,31 @@ public function via($notifiable)
*/
public function toMail($notifiable)
{
$url = $this->resetUrl($notifiable);

if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $this->token);
return call_user_func(static::$toMailCallback, $notifiable, $this->token, $url);
}

return $this->buildMailMessage($url);
}

/**
* Get the password reset URL for the given notifiable.
*
* @param mixed $notifiable
* @return string
*/
protected function resetUrl($notifiable)
{
if (static::$createUrlCallback) {
$url = call_user_func(static::$createUrlCallback, $notifiable, $this->token);
return call_user_func(static::$createUrlCallback, $notifiable, $this->token);
} else {
$url = url(route('password.reset', [
return url(route('password.reset', [
'token' => $this->token,
'email' => $notifiable->getEmailForPasswordReset(),
], false));
}

return $this->buildMailMessage($url);
}

/**
Expand Down

0 comments on commit 9eb835f

Please sign in to comment.