Laravel - 当我尝试重设密码时,我总是收到 'This password reset token is invalid'

Laravel - I keep getting 'This password reset token is invalid' when I try to reset password

这是我的 config/auth.php

 'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
        'customers' => [
            'provider' => 'customers',
            'table' => 'customer_password_resets',
            'expire' => 120,
        ],
        'admin' => [
            'provider' => 'admins',
            'table' => 'admin_password_resets',
            'expire' => 60,
        ],
    ],

尝试重置客户密码时,我收到错误消息“此令牌无效”。

这是我的 ResetsPassword.php -> reset()

 public function reset(Request $request)
    {
        $this->validate($request, $this->rules(), $this->validationErrorMessages());


        $response = $this->broker()->reset(
            $this->credentials($request), function ($user, $password) {
                $this->resetPassword($user, $password);
            }
        );


        return $response == Password::PASSWORD_RESET
                    ? $this->sendResetResponse($response)
                    : $this->sendResetFailedResponse($request, $response);
    }

这是密码重置请求:

必须在发布到 password.update 路由之前生成密码重置令牌。通常,当用户在发送密码重置 link.

之前将他们的电子邮件地址输入到表单中时,就会发生这种情况。

对于自定义实现,您可能需要手动生成令牌。

use Illuminate\Auth\Passwords\PasswordBroker;

// insert a token record into the password reset table
$token = app(PasswordBroker::class)->createToken($customer);

编辑: 令牌作为未散列值从代理返回,同时,它作为散列值存储在数据库中。确保 unhashed 令牌值作为参数 token 不带下划线提交给 reset() 方法,这与 CSRF _token 不同。

此外,您的 Customer 模型必须扩展 Authenticatable

class Customer extends Authenticatable
{
    // ...
}