【问题标题】:Laravel 6: How to change the URL of the password reset email link in custom classLaravel 6:如何在自定义类中更改密码重置电子邮件链接的 URL
【发布时间】:2021-02-21 12:51:19
【问题描述】:

我正在使用 Laravel 构建 API 并致力于重置密码。一切正常,但我想将处理重置链接的 URL 更改为不同于 API 域

Route::group(['namespace' => 'Api', 'middleware' => 'guest'], function () {
  Route::post('password/reset', 'ResetPasswordController')->name('password.reset');

public function forgotPassword($data) {
    Password::sendResetLink(['email' => $data['email']]);
}

Laravel 重置密码类(ResetPassword 类扩展 Notification)

 return (new MailMessage)
        ....
        ->action(Lang::get('Reset Password'), url(route('password.reset', ['token' => $this->token, 'email' => $notifiable->getEmailForPasswordReset()], false)))
        ....
}

我想更改网址

http://api.test:8000/api/password/reset?token=dced9b55a73fcd0692ce4157d2685826f51c332d0dcce613cad108a8599881d7&email=user@mail.com

成为

http://frontend.test:8000/reset-password?token=dced9b55a73fcd0692ce4157d2685826f51c332d0dcce613cad108a8599881d7&email=user@mail.com

我设法在原来的课程中改变了它

// ->action(Lang::get('Reset Password'), url(route('password.reset', ['token' => $this->token, 'email' => $notifiable->getEmailForPasswordReset()], false)))
->action(Lang::get('Reset Password'), 'http://frontend.test:8000/reset-password?token='.$this->token.'&email='.$notifiable->getEmailForPasswordReset())

但是我怎样才能在我自己的类中重写这个函数,这会更好地保持原来的函数,但不知道如何。

提前致谢

【问题讨论】:

    标签: api laravel-6 reset-password


    【解决方案1】:

    我在这里通过创建自定义通知并在 CanResetPassword trait https://laracasts.com/discuss/channels/laravel/how-to-override-the-tomail-function-in-illuminateauthnotificationsresetpasswordphp 中使用它找到了一个简单的答案

    【讨论】:

      猜你喜欢
      • 2021-02-07
      • 2019-05-25
      • 2017-03-27
      • 2021-02-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多