覆盖电子邮件模板 Laravel 5.3 中的密码重置 url
Override password reset url in email template Laravel 5.3
我正在尝试覆盖放入电子邮件中的 actionUrl 以重置用户帐户。但无论我做什么,它都保持不变。我尝试覆盖我的路线文件。有人可以帮我吗?
这是我的路线文件中的路线:
Route::get('cms/password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');
这是我的电子邮件模板:
<p style="{{ $style['paragraph-sub'] }}">
<a style="{{ $style['anchor'] }}" href="{{ $actionUrl }}" target="_blank">
{{ $actionUrl }}
</a>
</p>`
我知道 SimpleMessage.php 中定义了 actionUrl,但我不知道它的设置位置。
link设置在Illuminate\Auth\Notifications\ResetPassword
。这是针对密码重置请求发出的通知。
此通知在 Illuminate\Auth\Passwords\CanResetPassword
中初始化,这是在您的 App\User
模型中引入的特征。
所以您需要做的就是创建自己的重置通知并覆盖 User
模型上的 sendPasswordResetNotification
方法,如下所示:
php artisan make:notification MyResetPasswordNotification
编辑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.');
}
}
然后将其添加到 app/User.php
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new \App\Notifications\MyResetPasswordNotification($token));
}
当然,您需要创建自己的路线,正如您在问题中所写的那样,并且您还必须更改 blade 视图。
我正在尝试覆盖放入电子邮件中的 actionUrl 以重置用户帐户。但无论我做什么,它都保持不变。我尝试覆盖我的路线文件。有人可以帮我吗?
这是我的路线文件中的路线:
Route::get('cms/password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');
这是我的电子邮件模板:
<p style="{{ $style['paragraph-sub'] }}">
<a style="{{ $style['anchor'] }}" href="{{ $actionUrl }}" target="_blank">
{{ $actionUrl }}
</a>
</p>`
我知道 SimpleMessage.php 中定义了 actionUrl,但我不知道它的设置位置。
link设置在Illuminate\Auth\Notifications\ResetPassword
。这是针对密码重置请求发出的通知。
此通知在 Illuminate\Auth\Passwords\CanResetPassword
中初始化,这是在您的 App\User
模型中引入的特征。
所以您需要做的就是创建自己的重置通知并覆盖 User
模型上的 sendPasswordResetNotification
方法,如下所示:
php artisan make:notification MyResetPasswordNotification
编辑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.');
}
}
然后将其添加到 app/User.php
/**
* Send the password reset notification.
*
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
{
$this->notify(new \App\Notifications\MyResetPasswordNotification($token));
}
当然,您需要创建自己的路线,正如您在问题中所写的那样,并且您还必须更改 blade 视图。