【问题标题】:Laravel 6: How to override sendPasswordResetNotification functionLaravel 6:如何覆盖 sendPasswordResetNotification 函数
【发布时间】:2021-03-09 13:34:13
【问题描述】:

我一直在努力重置密码,但使用自定义通知而不是 Laravel 通知。这是文件vendor\laravel\framework\src\Illuminate\Auth\Passwords\CanResetPassword.php

 public function sendPasswordResetNotification($token)
{
    //use custom notification to change the url instead of modifying the original class
    //$this->notify(new ResetPasswordNotification($token));
    $this->notify(new CustomResetPassword($token));
}

这就是我在服务类中调用它

$reset_password_status = Password::reset($credentials, function ($user, $password) {
    $user->password = $password;
    $user->save();
});

if ($reset_password_status == Password::INVALID_TOKEN) {
    return $this->returnError->error("Invalid token provided");
}

但问题是在线构建项目是自动完成的,并且每次都运行 composer install 并且不能手动上传更改,所以我正在寻找一种方法来在我的代码中覆盖此功能以重置密码而不是编辑存在于供应商文件夹中的CanResetPassword.php 文件

【问题讨论】:

    标签: laravel reset-password


    【解决方案1】:

    在使用此特征的 Class 上,您可以覆盖此函数。类中编写的每个函数都优先于 trait 函数。

    【讨论】:

    • 我刚刚通过添加对密码重置的调用来更新代码。如何修改它以在此处使用自定义通知?
    • 感谢我设法覆盖它的提示
    • 如果你解决了你的问题,请接受回答,我会很高兴
    【解决方案2】:

    user.php 模型中

    public function sendPasswordResetNotification($token)
    {
        $this->notify(new CustomResetPassword($token));
    }
    

    【讨论】:

    • 如何设置$token
    猜你喜欢
    • 2017-09-11
    • 2020-07-05
    • 2015-04-13
    • 2011-07-21
    • 2016-05-04
    • 2012-10-16
    • 2020-07-13
    • 1970-01-01
    相关资源
    最近更新 更多